aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2020-10-03 20:45:55 +0100
committerGitHub <noreply@github.com>2020-10-03 20:45:55 +0100
commitfb0a4651f1be4ad936f8277478f73f262d8eeb72 (patch)
tree61ae020ab98e83d8b90b767fd617b9c7a216f840 /Lib/symtable.py
parentbpo-41922: Use PEP 590 vectorcall to speed up reversed() (GH-22523) (diff)
downloadcpython-fb0a4651f1be4ad936f8277478f73f262d8eeb72.tar.gz
cpython-fb0a4651f1be4ad936f8277478f73f262d8eeb72.tar.bz2
cpython-fb0a4651f1be4ad936f8277478f73f262d8eeb72.zip
bpo-41840: Report module-level globals as both local and global in the symtable module (GH-22391)
Diffstat (limited to 'Lib/symtable.py')
-rw-r--r--Lib/symtable.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/Lib/symtable.py b/Lib/symtable.py
index 9ff27ef74ff..98db1e2557d 100644
--- a/Lib/symtable.py
+++ b/Lib/symtable.py
@@ -39,7 +39,7 @@ class SymbolTableFactory:
_newSymbolTable = SymbolTableFactory()
-class SymbolTable(object):
+class SymbolTable:
def __init__(self, raw_table, filename):
self._table = raw_table
@@ -52,7 +52,7 @@ class SymbolTable(object):
else:
kind = "%s " % self.__class__.__name__
- if self._table.name == "global":
+ if self._table.name == "top":
return "<{0}SymbolTable for module {1}>".format(kind, self._filename)
else:
return "<{0}SymbolTable for {1} in {2}>".format(kind,
@@ -124,7 +124,9 @@ class SymbolTable(object):
if sym is None:
flags = self._table.symbols[name]
namespaces = self.__check_children(name)
- sym = self._symbols[name] = Symbol(name, flags, namespaces)
+ module_scope = (self._table.name == "top")
+ sym = self._symbols[name] = Symbol(name, flags, namespaces,
+ module_scope=module_scope)
return sym
def get_symbols(self):
@@ -214,13 +216,14 @@ class Class(SymbolTable):
return self.__methods
-class Symbol(object):
+class Symbol:
- def __init__(self, name, flags, namespaces=None):
+ def __init__(self, name, flags, namespaces=None, *, module_scope=False):
self.__name = name
self.__flags = flags
self.__scope = (flags >> SCOPE_OFF) & SCOPE_MASK # like PyST_GetScope()
self.__namespaces = namespaces or ()
+ self.__module_scope = module_scope
def __repr__(self):
return "<symbol {0!r}>".format(self.__name)
@@ -244,7 +247,8 @@ class Symbol(object):
def is_global(self):
"""Return *True* if the sysmbol is global.
"""
- return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT))
+ return bool(self.__scope in (GLOBAL_IMPLICIT, GLOBAL_EXPLICIT)
+ or (self.__module_scope and self.__flags & DEF_BOUND))
def is_nonlocal(self):
"""Return *True* if the symbol is nonlocal."""
@@ -258,7 +262,8 @@ class Symbol(object):
def is_local(self):
"""Return *True* if the symbol is local.
"""
- return bool(self.__scope in (LOCAL, CELL))
+ return bool(self.__scope in (LOCAL, CELL)
+ or (self.__module_scope and self.__flags & DEF_BOUND))
def is_annotated(self):
"""Return *True* if the symbol is annotated.