-
It's good that pyright is reporting this error, because otherwise, when treating But the problem is that I don't know how to specify it as immutable.
How can I specify that the variable doesn't change, but it can be overridden in the subclass so that the tooling knows the more specific type? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
As you point out, This wasn't an issue prior to pyright enforcing invariance for mutable fields. Mypy users will also encounter the problem when this feature is implemented in mypy. You may need to resort to a |
Beta Was this translation helpful? Give feedback.
As you point out,
Final
implies both "immutable" and "can't be overridden". In your use case, you want to indicate that the field is read-only but still overridable by subclasses. There has been some discussion about addingReadOnly
to the type system, but it hasn't gone very far.This wasn't an issue prior to pyright enforcing invariance for mutable fields. Mypy users will also encounter the problem when this feature is implemented in mypy.
You may need to resort to a
# type: ignore
to work around this current shortcoming in the type system.