GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-148406: Fix annotations of _colorize.FancyCompleter by danielhollas · Pull Request #148408 · python/cpython

Conversation

@danielhollas

@danielhollas danielhollas commented Apr 11, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #148406, using an approach suggested in the issue.

Test plan

Before

>>> import _colorize, pprint
>>> pprint.pprint(_colorize.FancyCompleter.__annotations__)
{'NoneType': '\x1b[1;32m',
 'bool': '\x1b[1;32m',
 'builtin_function_or_method': '\x1b[1;32m',
 'bytes': '\x1b[1;32m',
 'complex': '\x1b[1;32m',
 'float': '\x1b[1;32m',
 'function': '\x1b[1;32m',
 'int': '\x1b[1;32m',
 'method': '\x1b[1;32m',
 'method_descriptor': '\x1b[1;32m',
 'method_wrapper': '\x1b[1;32m',
 'module': '\x1b[1;32m',
 'str': '\x1b[1;32m',
 'type': '\x1b[1;32m',
 'wrapper_descriptor': '\x1b[1;32m'}

After

>>> from _colorize import FancyCompleter
>>> from pprint import pprint
>>> pprint(FancyCompleter.__annotations__)
{'NoneType': <class 'str'>,
 'bool': <class 'str'>,
 'builtin_function_or_method': <class 'str'>,
 'bytes': <class 'str'>,
 'complex': <class 'str'>,
 'float': <class 'str'>,
 'function': <class 'str'>,
 'int': <class 'str'>,
 'method': <class 'str'>,
 'method_descriptor': <class 'str'>,
 'method_wrapper': <class 'str'>,
 'module': <class 'str'>,
 'str': <class 'str'>,
 'type': <class 'str'>,
 'wrapper_descriptor': <class 'str'>}

Also added a regression tests to ensure that re module is not imported during _colorize import.
We've just made re import lazy in dataclasses (#148379), but because of the bug resolved here, it ended up being imported (because the annotations were strings, which was triggering the path that uses the re module).

  • Issue: Annotations of _colorize.FancyCompleter dataclass are funky #148406

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@danielhollas
Fix annotations of _colorize.FancyCompleter
2afcddc
@danielhollas
danielhollas requested a review from hugovk as a code owner April 11, 2026 23:12
@bedevere-app bedevere-app Bot added the awaiting review label Apr 11, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Apr 11, 2026
Annotations of _colorize.FancyCompleter dataclass are funky #148406
Closed
@danielhollas

danielhollas commented Apr 11, 2026

Copy link
Copy Markdown
Contributor Author

This is a change in a private module that should not be user facing so I don't think blurb is needed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

picnixz
picnixz reviewed Apr 11, 2026
View reviewed changes
Comment thread Lib/_colorize.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

sobolevn
sobolevn reviewed Apr 12, 2026
View reviewed changes

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more idea: there's a special section for type imports in if False: right below. Maybe you should utilize it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@DavidCEllis

DavidCEllis commented Apr 12, 2026

Copy link
Copy Markdown
Contributor

One more idea: there's a special section for type imports in if False: right below. Maybe you should utilize it?

I think that's only worth doing if the import is slow (so for typing it makes sense), otherwise you're just making the runtime annotations worse which will technically make the dataclass construction ever so slightly slower as get_annotations now has to build a bunch of ForwardRef objects1.

Footnotes

  1. I'm not sure if this would be measurable in context in _colorize ↩

AlexWaygood and danielhollas reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

hugovk
hugovk approved these changes Apr 13, 2026
View reviewed changes
Comment thread Lib/test/test__colorize.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Apr 13, 2026
@danielhollas @hugovk
Update Lib/test/test__colorize.py
0bbf214
Co-authored-by: Hugo van Kemenade <[email protected]>
@JelleZijlstra JelleZijlstra added the skip news label Apr 13, 2026
@hugovk
hugovk merged commit 4b33308 into python:main Apr 18, 2026
59 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 18, 2026
@danielhollas
danielhollas deleted the fix-fancy-completer branch April 18, 2026 19:51
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@danielhollas @hugovk @ljfp
pythongh-148406: Fix annotations of _colorize.FancyCompleter (python#…
5ee862a
…148408)

Co-authored-by: Hugo van Kemenade <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@sobolevn sobolevn sobolevn left review comments
@picnixz picnixz picnixz left review comments
@AlexWaygood AlexWaygood AlexWaygood left review comments
@hugovk hugovk hugovk approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Annotations of _colorize.FancyCompleter dataclass are funky

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@danielhollas @DavidCEllis @hugovk @sobolevn @picnixz @AlexWaygood @JelleZijlstra
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.