You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't recall where I saw this but I believe we had some example where a base class would declare a field of type float and the subclass would redefine it as int. I would just like to insert a note in that thread referencing python/mypy#3208, which points out that this is not actually a safe thing to do unless the class is immutable.
The text was updated successfully, but these errors were encountered:
Yes, but mypy currently only rejects this for protocols (which are deliberately more strict in some aspects), so technically speaking the example will pass, but I agree Any (probably in supertype) may be better for covariant mutable overriding example.
# Note that x from C1 replaces x in Base, but the order remains
# the same as defined in Base.
@dataclass
class Base:
x: float = 15.0
y: int = 0
@dataclass
class C1(Base):
z: int = 10
x: int = 15
I'm not sure we're using "super" and "sub" the same way here. Should the type of x be Any in base, or in C1?
I don't recall where I saw this but I believe we had some example where a base class would declare a field of type
float
and the subclass would redefine it asint
. I would just like to insert a note in that thread referencing python/mypy#3208, which points out that this is not actually a safe thing to do unless the class is immutable.The text was updated successfully, but these errors were encountered: