GeezerVison is showing github.com — gh-89547: Support for nesting special forms like Final by hmc-cs-mdrissi · Pull Request #116096 · python/cpython
Conversation
hmc-cs-mdrissi
commented
Feb 29, 2024
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Resolves this issue. The main goal was to permit ClassVar[Final[int]] and Final[ClassVar[int]]. This drops validation check that Final/ClassVar argument is not a special form.
This does allow some silly cases like ClassVar[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 so Union[ClassVar[int], int] remains forbidden and list[ClassVar[int]] is also forbidden. There already was a test case that list[ClassVar[int]] fails.
I also added couple tests for Annotated to ensure it can nest freely with ClassVar/Final.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
ghost
commented
Feb 29, 2024
•
edited by ghost
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
All commit authors signed the Contributor License Agreement. 
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
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?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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.
Thanks. I feel this should be treated as a new feature and not backported.
It's probably worth a versionchanged note in the typing docs, e.g. saying "ClassVar can now be nested inside Final".
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
AlexWaygood reacted with thumbs up emoji
|
@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.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
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 using ClassVar[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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
It's probably worth a versionchanged note in the typing docs, e.g. saying "ClassVar can now be nested inside Final".
This still needs to be done
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|