Message403617
Good idea to check with the PEP authors.
I don’t think allowing both ClassVar and Final in dataclasses requires general intersection types. Neither ClassVar nor Final are real types; they aren’t part of the type of the value. They are more like special annotations on a name, which are wrapped around a type as syntactic convenience. You’re right that it would require more than just amendment to the PEP text, though; it might require changes to type checkers, and it would also require changes to the runtime behavior of the `typing` module to special-case allowing `ClassVar[Final[…]]`. And the downside of this change is that it couldn’t be context sensitive to only be allowed in dataclasses. But I think this isn’t a big problem; type checkers could still error on that wrapping in non dataclass contexts if they want to.
But even if that change can’t be made, I think backwards compatibility still precludes changing the interpretation of `x: Final[int] = 3` on a dataclass, and it is more valuable to be able to specify Final instance attributes (fields) than final class attributes on dataclasses. |
|
| Date |
User |
Action |
Args |
| 2021-10-11 05:06:23 | carljm | set | recipients:
+ carljm, eric.smith, GBeauregard, saaketp |
| 2021-10-11 05:06:23 | carljm | set | messageid: <[email protected]> |
| 2021-10-11 05:06:23 | carljm | link | issue45384 messages |
| 2021-10-11 05:06:22 | carljm | create | |
|