Allow bare typing.ClassVar qualifiers#1931
Conversation
carljm
left a comment
There was a problem hiding this comment.
The substance of this looks good to me, thanks for the PR!
docs/spec/class-compat.rst
Outdated
| inferred as some type to which this value is :term:`assignable` (in this | ||
| case, either ``int``, ``Literal[2]``, or ``Any``). |
There was a problem hiding this comment.
The listed options are not the only choices here, I'd prefer not to imply that they are. (I think a strong case can be made that inferring Any | Literal[2] is the most correct option, from a gradual-typing perspective.) I'm fine with just listing the simpler options that you have here, but we shouldn't imply that it's an exhaustive list.
| inferred as some type to which this value is :term:`assignable` (in this | |
| case, either ``int``, ``Literal[2]``, or ``Any``). | |
| inferred as some type to which this value is :term:`assignable` (for example, | |
| ``int``, ``Literal[2]``, or ``Any``). |
There was a problem hiding this comment.
This is what I wanted to write out to begin with, but I realize my wording is wrong indeed :)
docs/spec/class-compat.rst
Outdated
| case, either ``int``, ``Literal[2]``, or ``Any``). | ||
|
|
||
| If the ``ClassVar`` qualifier is used without any assigned value, the type | ||
| should be inferred to an unknown static type (such as :ref:`Any`). |
There was a problem hiding this comment.
The only dynamic type discussed in the typing spec is Any, so it's a bit odd to imply here that there would be others. Most type checkers do distinguish between different "origins" of Any, and some do so with a variant of Any named Unknown, but as far as the spec is concerned these are all just Any.
| should be inferred to an unknown static type (such as :ref:`Any`). | |
| should be inferred as :ref:`Any`. |
There was a problem hiding this comment.
I was wondering if such a concept of an unknown static type, as written in the referenced any section:
typing/docs/spec/special-types.rst
Lines 6 to 14 in fafcdeb
would be worth specifying, and that's why I chose the same phrasing. But let's not complicate things, I'll go with Any.
|
This change to the spec looks reasonable to me. If this is accepted, someone will need to write conformance tests for it. @Viicos, if you're willing, you could include the conformance test updates in the same PR. |
0e355b7 to
97334a2
Compare
|
I created the TC request: python/typing-council#43. |
rchen152
left a comment
There was a problem hiding this comment.
Looks good to me! For what it's worth, a bare ClassVar with no assigned value looks a little fishy to me, but I suppose if x: ClassVar[int] with no value is allowed, allowing x: ClassVar makes sense.
|
All approved now, thanks Jukka! @Viicos would you mind regenerating version.toml etcetera? Unfortunately those are prone to meaningless merge conflicts. |
As per https://discuss.python.org/t/81705.