File: //usr/share/doc/python3.10-dev/html/library/symtable.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>symtable — Access to the compiler’s symbol tables — Python 3.10.12 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?2022.1" />
<script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.10.12 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="token — Constants used with Python parse trees" href="token.html" />
<link rel="prev" title="ast — Abstract Syntax Trees" href="ast.html" />
<link rel="canonical" href="file:///usr/share/doc/python3.10/html/library/symtable.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero"
d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="Quick search"/>
<input type="submit" value="Go"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">symtable</span></code> — Access to the compiler’s symbol tables</a><ul>
<li><a class="reference internal" href="#generating-symbol-tables">Generating Symbol Tables</a></li>
<li><a class="reference internal" href="#examining-symbol-tables">Examining Symbol Tables</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="ast.html"
title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code> — Abstract Syntax Trees</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="token.html"
title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">token</span></code> — Constants used with Python parse trees</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.10/Doc/library/symtable.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="token.html" title="token — Constants used with Python parse trees"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="ast.html" title="ast — Abstract Syntax Trees"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.10.12 Documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
<li class="nav-item nav-item-2"><a href="language.html" accesskey="U">Python Language Services</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">symtable</span></code> — Access to the compiler’s symbol tables</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="module-symtable">
<span id="symtable-access-to-the-compiler-s-symbol-tables"></span><h1><a class="reference internal" href="#module-symtable" title="symtable: Interface to the compiler's internal symbol tables."><code class="xref py py-mod docutils literal notranslate"><span class="pre">symtable</span></code></a> — Access to the compiler’s symbol tables<a class="headerlink" href="#module-symtable" title="Permalink to this headline">¶</a></h1>
<p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.10/Lib/symtable.py">Lib/symtable.py</a></p>
<hr class="docutils" />
<p>Symbol tables are generated by the compiler from AST just before bytecode is
generated. The symbol table is responsible for calculating the scope of every
identifier in the code. <a class="reference internal" href="#module-symtable" title="symtable: Interface to the compiler's internal symbol tables."><code class="xref py py-mod docutils literal notranslate"><span class="pre">symtable</span></code></a> provides an interface to examine these
tables.</p>
<section id="generating-symbol-tables">
<h2>Generating Symbol Tables<a class="headerlink" href="#generating-symbol-tables" title="Permalink to this headline">¶</a></h2>
<dl class="py function">
<dt class="sig sig-object py" id="symtable.symtable">
<span class="sig-prename descclassname"><span class="pre">symtable.</span></span><span class="sig-name descname"><span class="pre">symtable</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">filename</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">compile_type</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#symtable.symtable" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the toplevel <a class="reference internal" href="#symtable.SymbolTable" title="symtable.SymbolTable"><code class="xref py py-class docutils literal notranslate"><span class="pre">SymbolTable</span></code></a> for the Python source <em>code</em>.
<em>filename</em> is the name of the file containing the code. <em>compile_type</em> is
like the <em>mode</em> argument to <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a>.</p>
</dd></dl>
</section>
<section id="examining-symbol-tables">
<h2>Examining Symbol Tables<a class="headerlink" href="#examining-symbol-tables" title="Permalink to this headline">¶</a></h2>
<dl class="py class">
<dt class="sig sig-object py" id="symtable.SymbolTable">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">symtable.</span></span><span class="sig-name descname"><span class="pre">SymbolTable</span></span><a class="headerlink" href="#symtable.SymbolTable" title="Permalink to this definition">¶</a></dt>
<dd><p>A namespace table for a block. The constructor is not public.</p>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.get_type">
<span class="sig-name descname"><span class="pre">get_type</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.get_type" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the type of the symbol table. Possible values are <code class="docutils literal notranslate"><span class="pre">'class'</span></code>,
<code class="docutils literal notranslate"><span class="pre">'module'</span></code>, and <code class="docutils literal notranslate"><span class="pre">'function'</span></code>.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.get_id">
<span class="sig-name descname"><span class="pre">get_id</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.get_id" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the table’s identifier.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.get_name">
<span class="sig-name descname"><span class="pre">get_name</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.get_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the table’s name. This is the name of the class if the table is
for a class, the name of the function if the table is for a function, or
<code class="docutils literal notranslate"><span class="pre">'top'</span></code> if the table is global (<a class="reference internal" href="#symtable.SymbolTable.get_type" title="symtable.SymbolTable.get_type"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_type()</span></code></a> returns <code class="docutils literal notranslate"><span class="pre">'module'</span></code>).</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.get_lineno">
<span class="sig-name descname"><span class="pre">get_lineno</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.get_lineno" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the number of the first line in the block this table represents.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.is_optimized">
<span class="sig-name descname"><span class="pre">is_optimized</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.is_optimized" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the locals in this table can be optimized.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.is_nested">
<span class="sig-name descname"><span class="pre">is_nested</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.is_nested" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the block is a nested class or function.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.has_children">
<span class="sig-name descname"><span class="pre">has_children</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.has_children" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the block has nested namespaces within it. These can
be obtained with <a class="reference internal" href="#symtable.SymbolTable.get_children" title="symtable.SymbolTable.get_children"><code class="xref py py-meth docutils literal notranslate"><span class="pre">get_children()</span></code></a>.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.get_identifiers">
<span class="sig-name descname"><span class="pre">get_identifiers</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.get_identifiers" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a view object containing the names of symbols in the table.
See the <a class="reference internal" href="stdtypes.html#dict-views"><span class="std std-ref">documentation of view objects</span></a>.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.lookup">
<span class="sig-name descname"><span class="pre">lookup</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.lookup" title="Permalink to this definition">¶</a></dt>
<dd><p>Lookup <em>name</em> in the table and return a <a class="reference internal" href="#symtable.Symbol" title="symtable.Symbol"><code class="xref py py-class docutils literal notranslate"><span class="pre">Symbol</span></code></a> instance.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.get_symbols">
<span class="sig-name descname"><span class="pre">get_symbols</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.get_symbols" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of <a class="reference internal" href="#symtable.Symbol" title="symtable.Symbol"><code class="xref py py-class docutils literal notranslate"><span class="pre">Symbol</span></code></a> instances for names in the table.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.SymbolTable.get_children">
<span class="sig-name descname"><span class="pre">get_children</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.SymbolTable.get_children" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of the nested symbol tables.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="symtable.Function">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">symtable.</span></span><span class="sig-name descname"><span class="pre">Function</span></span><a class="headerlink" href="#symtable.Function" title="Permalink to this definition">¶</a></dt>
<dd><p>A namespace for a function or method. This class inherits
<a class="reference internal" href="#symtable.SymbolTable" title="symtable.SymbolTable"><code class="xref py py-class docutils literal notranslate"><span class="pre">SymbolTable</span></code></a>.</p>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Function.get_parameters">
<span class="sig-name descname"><span class="pre">get_parameters</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Function.get_parameters" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple containing names of parameters to this function.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Function.get_locals">
<span class="sig-name descname"><span class="pre">get_locals</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Function.get_locals" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple containing names of locals in this function.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Function.get_globals">
<span class="sig-name descname"><span class="pre">get_globals</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Function.get_globals" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple containing names of globals in this function.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Function.get_nonlocals">
<span class="sig-name descname"><span class="pre">get_nonlocals</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Function.get_nonlocals" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple containing names of nonlocals in this function.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Function.get_frees">
<span class="sig-name descname"><span class="pre">get_frees</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Function.get_frees" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple containing names of free variables in this function.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="symtable.Class">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">symtable.</span></span><span class="sig-name descname"><span class="pre">Class</span></span><a class="headerlink" href="#symtable.Class" title="Permalink to this definition">¶</a></dt>
<dd><p>A namespace of a class. This class inherits <a class="reference internal" href="#symtable.SymbolTable" title="symtable.SymbolTable"><code class="xref py py-class docutils literal notranslate"><span class="pre">SymbolTable</span></code></a>.</p>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Class.get_methods">
<span class="sig-name descname"><span class="pre">get_methods</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Class.get_methods" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a tuple containing the names of methods declared in the class.</p>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="symtable.Symbol">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">symtable.</span></span><span class="sig-name descname"><span class="pre">Symbol</span></span><a class="headerlink" href="#symtable.Symbol" title="Permalink to this definition">¶</a></dt>
<dd><p>An entry in a <a class="reference internal" href="#symtable.SymbolTable" title="symtable.SymbolTable"><code class="xref py py-class docutils literal notranslate"><span class="pre">SymbolTable</span></code></a> corresponding to an identifier in the
source. The constructor is not public.</p>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.get_name">
<span class="sig-name descname"><span class="pre">get_name</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.get_name" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the symbol’s name.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_referenced">
<span class="sig-name descname"><span class="pre">is_referenced</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_referenced" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is used in its block.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_imported">
<span class="sig-name descname"><span class="pre">is_imported</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_imported" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is created from an import statement.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_parameter">
<span class="sig-name descname"><span class="pre">is_parameter</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_parameter" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is a parameter.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_global">
<span class="sig-name descname"><span class="pre">is_global</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_global" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is global.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_nonlocal">
<span class="sig-name descname"><span class="pre">is_nonlocal</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_nonlocal" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is nonlocal.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_declared_global">
<span class="sig-name descname"><span class="pre">is_declared_global</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_declared_global" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is declared global with a global statement.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_local">
<span class="sig-name descname"><span class="pre">is_local</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_local" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is local to its block.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_annotated">
<span class="sig-name descname"><span class="pre">is_annotated</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_annotated" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is annotated.</p>
<div class="versionadded">
<p><span class="versionmodified added">New in version 3.6.</span></p>
</div>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_free">
<span class="sig-name descname"><span class="pre">is_free</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_free" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is referenced in its block, but not assigned
to.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_assigned">
<span class="sig-name descname"><span class="pre">is_assigned</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_assigned" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if the symbol is assigned to in its block.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.is_namespace">
<span class="sig-name descname"><span class="pre">is_namespace</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.is_namespace" title="Permalink to this definition">¶</a></dt>
<dd><p>Return <code class="docutils literal notranslate"><span class="pre">True</span></code> if name binding introduces new namespace.</p>
<p>If the name is used as the target of a function or class statement, this
will be true.</p>
<p>For example:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">table</span> <span class="o">=</span> <span class="n">symtable</span><span class="o">.</span><span class="n">symtable</span><span class="p">(</span><span class="s2">"def some_func(): pass"</span><span class="p">,</span> <span class="s2">"string"</span><span class="p">,</span> <span class="s2">"exec"</span><span class="p">)</span>
<span class="gp">>>> </span><span class="n">table</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s2">"some_func"</span><span class="p">)</span><span class="o">.</span><span class="n">is_namespace</span><span class="p">()</span>
<span class="go">True</span>
</pre></div>
</div>
<p>Note that a single name can be bound to multiple objects. If the result
is <code class="docutils literal notranslate"><span class="pre">True</span></code>, the name may also be bound to other objects, like an int or
list, that does not introduce a new namespace.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.get_namespaces">
<span class="sig-name descname"><span class="pre">get_namespaces</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.get_namespaces" title="Permalink to this definition">¶</a></dt>
<dd><p>Return a list of namespaces bound to this name.</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="symtable.Symbol.get_namespace">
<span class="sig-name descname"><span class="pre">get_namespace</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#symtable.Symbol.get_namespace" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the namespace bound to this name. If more than one namespace is
bound, <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> is raised.</p>
</dd></dl>
</dd></dl>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">symtable</span></code> — Access to the compiler’s symbol tables</a><ul>
<li><a class="reference internal" href="#generating-symbol-tables">Generating Symbol Tables</a></li>
<li><a class="reference internal" href="#examining-symbol-tables">Examining Symbol Tables</a></li>
</ul>
</li>
</ul>
<h4>Previous topic</h4>
<p class="topless"><a href="ast.html"
title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">ast</span></code> — Abstract Syntax Trees</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="token.html"
title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">token</span></code> — Constants used with Python parse trees</a></p>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.10/Doc/library/symtable.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="token.html" title="token — Constants used with Python parse trees"
>next</a> |</li>
<li class="right" >
<a href="ast.html" title="ast — Abstract Syntax Trees"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.10.12 Documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
<li class="nav-item nav-item-2"><a href="language.html" >Python Language Services</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">symtable</span></code> — Access to the compiler’s symbol tables</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
© <a href="../copyright.html">Copyright</a> 2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on August 15, 2025.
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.3.2.
</div>
</body>
</html>