Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lib/symtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ def get_namespace(self):


_flags = [('USE', USE)]
_flags.extend(kv for kv in globals().items() if kv[0].startswith('DEF_'))
_flags.extend(kv for kv in vars(_symtable).items() if kv[0].startswith('DEF_'))
_scopes_names = ('FREE', 'LOCAL', 'GLOBAL_IMPLICIT', 'GLOBAL_EXPLICIT', 'CELL')
_scopes_value_to_name = frozendict({globals()[n]: n for n in _scopes_names})
_scopes_value_to_name = frozendict({getattr(_symtable, n): n for n in _scopes_names})


def main(args):
Expand Down
1 change: 0 additions & 1 deletion Lib/test/lazy_imports_all_exclude.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ test_profile
test_profiling
test_pyrepl
test_subprocess
test_symtable
test_tools
test_type_annotations
test_unittest
10 changes: 10 additions & 0 deletions Lib/test/test_symtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from test import support
from test.support import os_helper
from test.support.script_helper import assert_python_ok


TEST_CODE = """
Expand Down Expand Up @@ -446,6 +447,15 @@ def test_symbol_repr(self):
self.assertEqual(repr(class_A.lookup('x')),
"<symbol 'x': LOCAL, DEF_LOCAL|DEF_FREE_CLASS>")

@support.requires_subprocess()
def test_symbol_repr_lazy_imports(self):
Comment thread
anistark marked this conversation as resolved.
Resolved
# See https://github.com/python/cpython/issues/160810.
code = ("import symtable\n"
"top = symtable.symtable('x = 1', '?', 'exec')\n"
"print(repr(top.lookup('x')))\n")
_, out, _ = assert_python_ok('-X', 'lazy_imports=all', '-c', code)
self.assertEqual(out.strip(), b"<symbol 'x': LOCAL, DEF_LOCAL>")

def test_symtable_entry_repr(self):
expected = f"<symtable entry top({self.top.get_id()}), line {self.top.get_lineno()}>"
self.assertEqual(repr(self.top._table), expected)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix :func:`repr` of :class:`symtable.Symbol` raising :exc:`TypeError` when
all imports are lazy (``-X lazy_imports=all``).
Loading