Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

bpo-46553: allow bare typing.ClassVar annotations#30983

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gvanrossum merged 3 commits intopython:mainfromGBeauregard:fix-classvar-bare
Jan 28, 2022

Conversation

@GBeauregard
Copy link
Contributor

@GBeauregardGBeauregard commentedJan 28, 2022
edited
Loading

This is a simple matter of just addingClassVar to the list of types allowed to be bare before the later call that raises for bare types.

These are used in the wild and covered by dataclasses unit tests.
Several static type checkers support this pattern.

Note we adjust one test fromClassVar[ClassVar] to
ClassVar[ClassVar[int]] so that it still fails. This is surprising, but
not a result of weirdness we're doing in this patch. This is a
limitation of the current way runtime type checking works that this case
is allowed when bare special forms are allowed. For example, before this
patchClassVar[Final] is a valid runtime annotation despite nesting these
forms being generally disallowed, so it's expected allowing bareClassVar
makesClassVar[ClassVar] valid as well.

https://bugs.python.org/issue46553

These are used in the wild and covered by dataclasses unit tests.Several static type checkers support this pattern.Note we adjust one test from ClassVar[ClassVar] toClassVar[ClassVar[int]] so that it still fails. This is surprising, butnot a result of weirdness we're doing in this patch. This is alimitation of the current way runtime type checking works that this caseis allowed when bare special forms are allowed. For example, before thispatch `ClassVar[Final]` is a valid annotation despite nesting theseforms being generally disallowed. Addressing this limitation could befuture work.
@GBeauregardGBeauregard changed the titletyping: allow bare ClassVar annotationsbpo-46553: allow bare typing.ClassVar annotationsJan 28, 2022
@bedevere-bot
Copy link

@gvanrossum: Please replace# withGH- in the commit message next time. Thanks!

@GBeauregardGBeauregard deleted the fix-classvar-bare branchFebruary 6, 2022 09:03
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@gvanrossumgvanrossumgvanrossum approved these changes

@Fidget-SpinnerFidget-SpinnerAwaiting requested review from Fidget-Spinner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@GBeauregard@bedevere-bot@gvanrossum@the-knights-who-say-ni

[8]ページ先頭

©2009-2025 Movatter.jp