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
Loosen base class attribute compatibility checks when attribute is redefined (#6585)
This eliminates the error `Definition of "Nested" in base class "Base1" is incompatible with definition in base class "Base2"` in the following code, where `Nested` is redefined in `A`:
```
from typing import TypeVar, Generic
T = TypeVar('T', covariant=True)
class GenericBase(Generic[T]):
pass
class Base1:
Nested: GenericBase['Base1']
class Base2:
Nested: GenericBase['Base2']
class A(Base1, Base2):
Nested: GenericBase['A']
```
- In the case of multiple inheritance, don't give errors about definitions of an
attribute in base classes being incompatible when the attribute is redefined.
The redefinition must itself be compatible with all (non-type-ignored)
definitions of the attribute in all base classes.
This is achieved by making the following change to checking of incompatible
types in assignments.
- Don't stop checking after the first base where the attribute is defined
when checking for incompatible types in assignments.
There is still a maximum of one "Incompatible type in assignment" error
per assignment.
Resolves#2619
main:10: error: Incompatible types in assignment (expression has type "GenericBase[Base1]", base class "Base2" defined the type as "GenericBase[Base2]")
main:10: error: Incompatible types in assignment (expression has type "GenericBase[Base2]", base class "Base1" defined the type as "GenericBase[Base1]")
0 commit comments