Title: Annotations of `_colorize.FancyCompleter` dataclass are funky · Issue #148406 · python/cpython · GitHub
Open Graph Title: Annotations of `_colorize.FancyCompleter` dataclass are funky · Issue #148406 · python/cpython
X Title: Annotations of `_colorize.FancyCompleter` dataclass are funky · Issue #148406 · python/cpython
Description: Bug report Bug description: There's no easy way to describe this, but the recently added FancyCompleter dataclass` annotations are perhaps too fancy 😅 >>> import _colorize, pprint >>> pprint.pprint(_colorize.FancyCompleter.__annotations_...
Open Graph Description: Bug report Bug description: There's no easy way to describe this, but the recently added FancyCompleter dataclass` annotations are perhaps too fancy 😅 >>> import _colorize, pprint >>> pprint.pprint...
X Description: Bug report Bug description: There's no easy way to describe this, but the recently added FancyCompleter dataclass` annotations are perhaps too fancy 😅 >>> import _colorize, pprint >...
Opengraph URL: https://github.com/python/cpython/issues/148406
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Annotations of `_colorize.FancyCompleter` dataclass are funky","articleBody":"# Bug report\n\n### Bug description:\n\nThere's no easy way to describe this, but the recently added FancyCompleter dataclass` annotations are perhaps too fancy 😅 \n\n```python\n>>> import _colorize, pprint\n>>> pprint.pprint(_colorize.FancyCompleter.__annotations__)\n{'NoneType': '\\x1b[1;32m',\n 'bool': '\\x1b[1;32m',\n 'builtin_function_or_method': '\\x1b[1;32m',\n 'bytes': '\\x1b[1;32m',\n 'complex': '\\x1b[1;32m',\n 'float': '\\x1b[1;32m',\n 'function': '\\x1b[1;32m',\n 'int': '\\x1b[1;32m',\n 'method': '\\x1b[1;32m',\n 'method_descriptor': '\\x1b[1;32m',\n 'method_wrapper': '\\x1b[1;32m',\n 'module': '\\x1b[1;32m',\n 'str': '\\x1b[1;32m',\n 'type': '\\x1b[1;32m',\n 'wrapper_descriptor': '\\x1b[1;32m'}\n```\n\nThe problem is the following attribute\n\n```\n str: str = ANSIColors.BOLD_GREEN\n```\n\nRemoving this attribute results in expected behaviour\n\n```\n>>> import _colorize, pprint\n>>> pprint.pprint(_colorize.FancyCompleter.__annotations__)\n{'NoneType': \u003cclass 'str'>,\n 'bool': \u003cclass 'str'>,\n 'builtin_function_or_method': \u003cclass 'str'>,\n 'bytes': \u003cclass 'str'>,\n 'complex': \u003cclass 'str'>,\n 'float': \u003cclass 'str'>,\n 'function': \u003cclass 'str'>,\n 'int': \u003cclass 'str'>,\n 'method': \u003cclass 'str'>,\n 'method_descriptor': \u003cclass 'str'>,\n 'method_wrapper': \u003cclass 'str'>,\n 'module': \u003cclass 'str'>,\n 'type': \u003cclass 'str'>,\n 'wrapper_descriptor': \u003cclass 'str'>}\n```\n\nIt looks like the overwriting of the `str` type is an expected behaviour of the [annotation scopes](https://docs.python.org/3/reference/executionmodel.html#annotation-scopes).\nQuoting from @JelleZijlstra 's blog about implementing PEP 695 - https://jellezijlstra.github.io/pep695.html\n\n> When Alias is evaluated, we’ll expect to resolve T from a cell variable (created by the annotation scope for the class’s type parameters), so we use LOAD_CLASSDICT_OR_DEREF, and int from the builtins, so we use LOAD_CLASSDICT_OR_GLOBAL. But in both cases, we need to account for the possibility that the class namespace was modified to inject a value for T or int before we evaluate the value of the type alias; that is why we need to first look at __classdict__.\n\nI am not sure what is the best non-hacky solution here.\nA hacky solution could be to use a different attribute name (e.g. `string`) and special-case the code in PyREPL that uses FancyCompleter. Happy to submit a PR unless somebody else has a better idea.\n\n### CPython versions tested on:\n\nCPython main branch\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-148408\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/danielhollas","@type":"Person","name":"danielhollas"},"datePublished":"2026-04-11T22:26:52Z","url":"https://github.com/python/cpython/issues/148406"}
| 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:f3fdc567-4af0-61f8-ec9e-3a8d8f6a2ee4 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EAA4:2270F4:377D340:4990EBF:6B020AD3 |
| html-safe-nonce | dd86445616ef92afeffb1240131c80c394a8cd0c16f429c586b6862238d0ca8e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUE0OjIyNzBGNDozNzdEMzQwOjQ5OTBFQkY6NkIwMjBBRDMiLCJ2aXNpdG9yX2lkIjoiNDc3NjI2MjkxMzUzMzAyMDg4MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ee22a1b61bfc75efc0fd676b7ba201a5f42837db99c472ea0f4f2b13fc68aec7 |
| hovercard-subject-tag | issue:4245915828 |
| 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/148406/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9e883f08ea03a3b56ff8c0467053f155e262346f75f7c4944988c999babe569f/python/cpython/issues/148406 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9e883f08ea03a3b56ff8c0467053f155e262346f75f7c4944988c999babe569f/python/cpython/issues/148406 |
| og:image:alt | Bug report Bug description: There's no easy way to describe this, but the recently added FancyCompleter dataclass` annotations are perhaps too fancy 😅 >>> import _colorize, pprint >>> pprint.pprint... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | danielhollas |
| 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