Is it type-safe for a subclass to annotate an attribute as Never?
#1443
Replies: 2 comments 3 replies
|
What all parties agree on is:
Disagreement is about whether if Pro:
|
|
Speaking to the general case: Covariant overriding of mutable attributes is something that is definitely unsound. However, most type checkers allow it in cases involving nominal subtyping, see e.g. python/mypy#3208. This is a decision made for pragmatic reasons. With Protocols and substructural typing, we got an opportunity to be stricter, and I believe most type checkers disallow covariant overriding of mutable attributes in substructural types. I haven't followed the intersection discussion closely since it was too noisy. My advice would be to first focus on intersections of structural types. This would cover a lot of the usage, and you choose soundness on things like covariant overrides of mutable attributes. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Consider this example ①:
Is
Ba proper subtype ofA? Bothmypyandpyrightdo not flag this code as wrong, but there is a heated debate in the intersection-pep discussion whether this is allowed. I would appreciate it if people could comment on what they think whether in the examples ①, ②, ③, ④Bis a proper subtype ofA. (all examples validate inmypyandpyright).Example ②
Example ③
Example ④
All reactions