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

gh-89547: Support for nesting special forms like Final#116096

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

Conversation

hmc-cs-mdrissi
Copy link
Contributor

@hmc-cs-mdrissihmc-cs-mdrissi commentedFeb 29, 2024
edited by bedevere-appbot
Loading

Resolves thisissue. The main goal was to permitClassVar[Final[int]] andFinal[ClassVar[int]]. This drops validation check that Final/ClassVar argument is not a special form.

This does allow some silly cases likeClassVar[ClassVar[int]] but I think it's simpler to allow them then have more complex validation rules at runtime. I did not remove special form check for other forms soUnion[ClassVar[int], int] remains forbidden andlist[ClassVar[int]] is also forbidden. There already was a test case thatlist[ClassVar[int]] fails.

I also added couple tests for Annotated to ensure it can nest freely withClassVar/Final.

@ghost
Copy link

ghost commentedFeb 29, 2024
edited by ghost
Loading

All commit authors signed the Contributor License Agreement.
CLA signed

Copy link
Member

@AlexWaygoodAlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Wow, that's an easy change to make! Not sure if we want to treat this as a new feature or a backportable bugfix — thoughts,@JelleZijlstra?

Copy link
Member

@JelleZijlstraJelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks. I feel this should be treated as a new feature and not backported.

It's probably worth aversionchanged note in the typing docs, e.g. saying "ClassVar can now be nested inside Final".

AlexWaygood reacted with thumbs up emoji
@carljm
Copy link
Member

@JelleZijlstra what do you see as the risk of backporting?

It seems like arguably a "bug" that (given the current de facto behavior of type checkers) there is no way to specify a Final, non-field, ClassVar, on a dataclass. Backporting this would fix that "bug" for all users of Python 3.11 and Python 3.12, rather than requiring they wait until 3.13.

@JelleZijlstra
Copy link
Member

It feels like a new feature to me; we're adding support for something that wasn't previously allowed. For example, if a library after the release of 3.12.3 starts usingClassVar[Final...] in its code and tests only on 3.12.3+, they would break all users who are still on 3.12.2 without realizing it.

Users on earlier versions can work around the problem by using quoted annotations.

carljm, AlexWaygood, and JWCS reacted with thumbs up emoji

@AlexWaygood
Copy link
Member

It's probably worth aversionchanged note in the typing docs, e.g. saying "ClassVar can now be nested inside Final".

This still needs to be done

@JelleZijlstra
Copy link
Member

Thanks, done in#116686

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@AlexWaygoodAlexWaygoodAlexWaygood left review comments

@JelleZijlstraJelleZijlstraJelleZijlstra approved these changes

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

5 participants
@hmc-cs-mdrissi@carljm@JelleZijlstra@AlexWaygood@Eclips4

[8]ページ先頭

©2009-2025 Movatter.jp