-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Allow to use Final and ClassVar after python 3.13 #18358
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
Conversation
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
Thank you!
mypy/typeanal.py
Outdated
@@ -605,7 +605,7 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Typ | |||
t, | |||
code=codes.VALID_TYPE, | |||
) | |||
else: | |||
elif self.options.python_version < (3, 13): |
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.
We should still error in several of the cases this previously triggered, e.g. def f(x: Final[int]) -> int: ...
(grep the test cases for Final can be only used as an outermost qualifier
for examples)
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
mypy/semanal.py
Outdated
@@ -5080,7 +5084,9 @@ def check_classvar(self, s: AssignmentStmt) -> None: | |||
node = lvalue.node | |||
if isinstance(node, Var): | |||
node.is_classvar = True | |||
analyzed = self.anal_type(s.type) | |||
analyzed = self.anal_type( | |||
s.type, allow_final_in_classvar=self.options.python_version >= (3, 13) |
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.
I think this one might be unnecessary? Let me push to your PR
for more information, see https://pre-commit.ci
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.
Thank you for this improvement!
@hauntsaninja Thank you very much! |
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Hi, Thanks for making a great library! I've been using mypy for years and it saved me from several (possibly happened) accidents!
Description
this PR allows to use Final and ClassVar after python 3.13
I saw this PR
and I saw recent changes of python 3.13

https://docs.python.org/3/library/typing.html#typing.Final
Final now can be nested with ClassVar. so I added a version check!