Skip to content

enforce Liskov Substitution Principle on subclasses #166

@carljm

Description

@carljm

This means checking that subclass methods are subtypes of the superclass method they override, if any.

Subclass property getters must return a subtype of the corresponding superclass property getters, and subclass property setters must accept a supertype of the corresponding superclass property setter.

If we model any mutable attribute as conceptually a property with getter and setter, where the setter accepts the same type that the getter returns, this implies that the type of mutable attributes must be invariant; that is, subclasses may neither widen nor narrow the type of the attribute. Pyright models this correctly; mypy does not.

See #167 for a demonstration of a particular case involving ClassVar.

Sub-issues

Metadata

Metadata

Assignees

Labels

typing semanticstyping-module features, spec compliance, etc

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions