Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Annotated to wrap Final and ClassVar #577

Closed
GBeauregard opened this issue Jan 25, 2022 · 2 comments
Closed

Allow Annotated to wrap Final and ClassVar #577

GBeauregard opened this issue Jan 25, 2022 · 2 comments
Assignees

Comments

@GBeauregard
Copy link

GBeauregard commented Jan 25, 2022

Pyre Bug

Bug description
The behavior of Annotated has been changed so that it is allowed at runtime to wrap ClassVar and Final. This change helps avoid friction with other users of annotations; see https://bugs.python.org/issue46491 for context. This change has landed in 3.11 and has been backported to 3.9, 3.10, and typing_extensions. pyre should follow suit in allowing the wrapping in order to allow the friction lifting to happen in practice.

Reproduction steps

from typing import Annotated, ClassVar, Final

class C:
    classvar: Annotated[ClassVar[int], (2, 5)] = 4
    const: Annotated[Final[int], "metadata"] = 4

Expected behavior
The above code should type check.

Logs
Please include any relevant logs here:

antest/antest.py:4:4 Incompatible attribute type [8]: Attribute `classvar` declared in class `C` has type `typing.Annotated[ClassVar[int]]` but is used as type `int`.
antest/antest.py:5:4 Incompatible attribute type [8]: Attribute `const` declared in class `C` has type `typing.Annotated[Final[int]]` but is used as type `int`.
antest/antest.py:5:4 Invalid type [31]: Expression `typing.Annotated[Final[int]]` is not a valid type. Final cannot be nested.

Additional context
Client version: 0.9.10
Binary version: d418f5bb10fdee9648eeea3834c8ca56944bd2ce
Corresponding issue for dataclasses (incl InitVar) is at https://bugs.python.org/issue46511
pyright change: microsoft/pyright@8ce7fa6
mypy bug: python/mypy#12061
pytype bug: google/pytype#1110

@stroxler
Copy link
Contributor

Great, thanks @GBeauregard for flagging this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants