@@ -1605,6 +1605,16 @@ def check_multiple_inheritance(self, typ: TypeInfo) -> None:
1605
1605
if name in base2 .names and base2 not in base .mro :
1606
1606
self .check_compatibility (name , base , base2 , typ )
1607
1607
1608
+ def _determine_type_of_class_member (self , sym : SymbolTableNode ) -> Optional [Type ]:
1609
+ if sym .type is not None :
1610
+ return sym .type
1611
+ if isinstance (sym .node , FuncBase ):
1612
+ return self .function_type (sym .node )
1613
+ if isinstance (sym .node , TypeInfo ):
1614
+ # nested class
1615
+ return type_object_type (sym .node , self .named_type )
1616
+ return None
1617
+
1608
1618
def check_compatibility (self , name : str , base1 : TypeInfo ,
1609
1619
base2 : TypeInfo , ctx : Context ) -> None :
1610
1620
"""Check if attribute name in base1 is compatible with base2 in multiple inheritance.
@@ -1618,12 +1628,12 @@ def check_compatibility(self, name: str, base1: TypeInfo,
1618
1628
return
1619
1629
first = base1 [name ]
1620
1630
second = base2 [name ]
1621
- first_type = first .type
1622
- if first_type is None and isinstance ( first . node , FuncBase ):
1623
- first_type = self . function_type ( first . node )
1624
- second_type = second . type
1625
- if second_type is None and isinstance (second . node , FuncBase ):
1626
- second_type = self . function_type ( second . node )
1631
+ if isinstance ( first .node , TypeInfo ) and isinstance ( second . node , TypeInfo ):
1632
+ # allow nested classes with the same name
1633
+ return
1634
+ first_type = self . _determine_type_of_class_member ( first )
1635
+ second_type = self . _determine_type_of_class_member (second )
1636
+
1627
1637
# TODO: What if some classes are generic?
1628
1638
if (isinstance (first_type , FunctionLike ) and
1629
1639
isinstance (second_type , FunctionLike )):
0 commit comments