@@ -1145,7 +1145,28 @@ def analyze_base_classes(self, defn: ClassDef) -> None:
11451145 return
11461146 # TODO: Ideally we should move MRO calculation to a later stage, but this is
11471147 # not easy, see issue #5536.
1148- calculate_class_mro (defn , self .fail_blocker , self .object_type )
1148+ self .calculate_class_mro (defn , self .object_type )
1149+
1150+ def calculate_class_mro (self , defn : ClassDef ,
1151+ obj_type : Optional [Callable [[], Instance ]] = None ) -> None :
1152+ """Calculate method resolution order for a class.
1153+
1154+ `obj_type` may be omitted in the third pass when all classes are already analyzed.
1155+ It exists just to fill in empty base class list during second pass in case of
1156+ an import cycle.
1157+ """
1158+ try :
1159+ calculate_mro (defn .info , obj_type )
1160+ except MroError :
1161+ self .fail_blocker ('Cannot determine consistent method resolution '
1162+ 'order (MRO) for "%s"' % defn .name , defn )
1163+ defn .info .mro = []
1164+ # Allow plugins to alter the MRO to handle the fact that `def mro()`
1165+ # on metaclasses permits MRO rewriting.
1166+ if defn .fullname :
1167+ hook = self .plugin .get_customize_class_mro_hook (defn .fullname )
1168+ if hook :
1169+ hook (ClassDefContext (defn , Expression (), self ))
11491170
11501171 def update_metaclass (self , defn : ClassDef ) -> None :
11511172 """Lookup for special metaclass declarations, and update defn fields accordingly.
@@ -3428,22 +3449,6 @@ def refers_to_class_or_function(node: Expression) -> bool:
34283449 isinstance (node .node , (TypeInfo , FuncDef , OverloadedFuncDef )))
34293450
34303451
3431- def calculate_class_mro (defn : ClassDef , fail : Callable [[str , Context ], None ],
3432- obj_type : Optional [Callable [[], Instance ]] = None ) -> None :
3433- """Calculate method resolution order for a class.
3434-
3435- `obj_type` may be omitted in the third pass when all classes are already analyzed.
3436- It exists just to fill in empty base class list during second pass in case of
3437- an import cycle.
3438- """
3439- try :
3440- calculate_mro (defn .info , obj_type )
3441- except MroError :
3442- fail ("Cannot determine consistent method resolution order "
3443- '(MRO) for "%s"' % defn .name , defn )
3444- defn .info .mro = []
3445-
3446-
34473452def calculate_mro (info : TypeInfo , obj_type : Optional [Callable [[], Instance ]] = None ) -> None :
34483453 """Calculate and set mro (method resolution order).
34493454
0 commit comments