Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Annotations of _colorize.FancyCompleter dataclass are funky聽#148406

Copy link
Copy link
@danielhollas

Description

@danielhollas
Issue body actions

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__)
{'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'}

The problem is the following attribute

    str: str = ANSIColors.BOLD_GREEN

Removing this attribute results in expected behaviour

>>> import _colorize, pprint
>>> pprint.pprint(_colorize.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'>,
 'type': <class 'str'>,
 'wrapper_descriptor': <class 'str'>}

It looks like the overwriting of the str type is an expected behaviour of the annotation scopes.
Quoting from @JelleZijlstra 's blog about implementing PEP 695 - https://jellezijlstra.github.io/pep695.html

When Alias is evaluated, we鈥檒l expect to resolve T from a cell variable (created by the annotation scope for the class鈥檚 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.

I am not sure what is the best non-hacky solution here.
A 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.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.