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:
|
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
Consider this example ①:
Is
B
a proper subtype ofA
? Bothmypy
andpyright
do 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 ①, ②, ③, ④B
is a proper subtype ofA
. (all examples validate inmypy
andpyright
).Example ②
Example ③
Example ④
Beta Was this translation helpful? Give feedback.
All reactions