Sorry, something went wrong.
Sorry, something went wrong.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@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.
|
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. |
Sorry, something went wrong.
|
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.
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.