◐ Shell
clean mode source ↗

gh-89547: Support for nesting special forms like Final by hmc-cs-mdrissi · Pull Request #116096 · python/cpython

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.