Title: symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all · Issue #160810 · python/cpython · GitHub
Open Graph Title: symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all · Issue #160810 · python/cpython
X Title: symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all · Issue #160810 · python/cpython
Description: Bug report Bug description: With -X lazy_imports=all, repr() of a symtable.Symbol raises TypeError: import symtable top = symtable.symtable('x = 1', '
Open Graph Description: Bug report Bug description: With -X lazy_imports=all, repr() of a symtable.Symbol raises TypeError: import symtable top = symtable.symtable('x = 1', '
X Description: Bug report Bug description: With -X lazy_imports=all, repr() of a symtable.Symbol raises TypeError: import symtable top = symtable.symtable('x = 1', '<string>', 'exec'...
Opengraph URL: https://github.com/python/cpython/issues/160810
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"symtable: repr() of a Symbol raises TypeError under -X lazy_imports=all","articleBody":"# Bug report\n\n### Bug description:\n\nWith `-X lazy_imports=all`, `repr()` of a `symtable.Symbol` raises `TypeError`:\n\n```python\nimport symtable\ntop = symtable.symtable('x = 1', '\u003cstring>', 'exec')\nprint(top.get_symbols())\n```\n\n```\n$ ./python -X lazy_imports=all repro.py\nTraceback (most recent call last):\n File \"repro.py\", line 3, in \u003cmodule>\n print(top.get_symbols())\n ~~~~~^^^^^^^^^^^^^^^^^^^\n File \"Lib/symtable.py\", line 264, in __repr__\n flags_str = '|'.join(self._flags_str())\n File \"Lib/symtable.py\", line 272, in _flags_str\n if self.__flags & flagvalue == flagvalue:\n ~~~~~~~~~~~~~^~~~~~~~~~~\nTypeError: unsupported operand type(s) for &: 'int' and 'lazy_import'\n```\n\nWithout the option it prints `[\u003csymbol 'x': LOCAL, DEF_LOCAL>]`.\n\n`Lib/symtable.py` builds its `_flags` and `_scopes_value_to_name` tables from `globals()`: https://github.com/python/cpython/blob/c79146a9eb05dea735a6a22dc004379cdec3ed0e/Lib/symtable.py#L388-L391\n\nWith `lazy_imports=all`, the `from _symtable import ...` at the top of the module is lazy, so `globals()` holds `lazy_import` objects instead of the integer constants. `_flags` breaks `repr()` as above, and once that is fixed, `_scopes_value_to_name` still makes the scope print as `1` instead of `LOCAL`.\n\nThis is the `test_symtable` failure mentioned in gh-149640, and why `test_symtable` is in `Lib/test/lazy_imports_all_exclude.txt`. The 3.15 branch has the same code.\n\nPossible fix: take the values from the `_symtable` module (for example `getattr(_symtable, name)`) instead of from `globals()`. With that, `test_symtable` passes with and without `-X lazy_imports=all` and can come off the exclusion list. I can open a PR if this sounds right.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-160866\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/anistark","@type":"Person","name":"anistark"},"datePublished":"2026-10-28T08:22:40Z","url":"https://github.com/python/cpython/issues/160810"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3a0ca825-670b-e338-70ea-828f896d606c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EC16:D4E59:5C6338:749457:6B01FE20 |
| html-safe-nonce | 60156c2e8958ea3d1efe63d1164856c6ecac478ac7c476f50714eaf49cc77c8a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQzE2OkQ0RTU5OjVDNjMzODo3NDk0NTc6NkIwMUZFMjAiLCJ2aXNpdG9yX2lkIjoiMTYwNDQ2MDA0MjUyNDk1MDA0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7645ca8a5393d61674678ad1e1d3e55d6d3cc1dfe3629f2ddc3cf2b3223fa178 |
| hovercard-subject-tag | issue:6075266308 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/160810/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c06e3c712baf8498b7dc1be3c8d940a19458a19e5d0f9612c3d71af85b0735b4/python/cpython/issues/160810 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c06e3c712baf8498b7dc1be3c8d940a19458a19e5d0f9612c3d71af85b0735b4/python/cpython/issues/160810 |
| og:image:alt | Bug report Bug description: With -X lazy_imports=all, repr() of a symtable.Symbol raises TypeError: import symtable top = symtable.symtable('x = 1', ' |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | anistark |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width