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 #12061

Open
GBeauregard opened this issue Jan 25, 2022 · 3 comments
Open

Allow Annotated to wrap Final and ClassVar #12061

GBeauregard opened this issue Jan 25, 2022 · 3 comments
Labels
bug mypy got something wrong topic-final PEP 591

Comments

@GBeauregard
Copy link

GBeauregard commented Jan 25, 2022

Bug Report

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. mypy should follow suit in allowing the wrapping in order to allow the friction lifting to happen in practice.

To Reproduce

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.

Actual Behavior

antest/antest.py:4: error: Invalid type: ClassVar nested inside other type
antest/antest.py:5: error: Final can be only used as an outermost qualifier in a variable annotation
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.931
  • Mypy command-line flags: none
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: 3.9.9
  • Operating system and version: Gentoo Linux stable

Additional Context
Corresponding issue for dataclasses (incl InitVar) is at https://bugs.python.org/issue46511
pyright changed at microsoft/pyright@8ce7fa6
pytype issue at google/pytype#1110
pyre issue at facebook/pyre-check#577

@hmc-cs-mdrissi
Copy link
Contributor

I'd like to take this task. I'm pretty happy my comment led to this change so I'm happy to cover the pr. I'll try to do it this weekend.

@JWCS
Copy link

JWCS commented Mar 27, 2024

@hmc-cs-mdrissi Is this resolved now with #116069?

@hmc-cs-mdrissi
Copy link
Contributor

No. That is related (but little different) python typing runtime change, while this issue is for type checker change. I'd forgotten about this mypy issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-final PEP 591
Projects
None yet
Development

No branches or pull requests

4 participants