Skip to content

Commit c85fe85

Browse files
committed
Don't iterate over the MRO when only bases are needed
1 parent 1ad4f76 commit c85fe85

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

mypy/semanal.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,14 +1196,13 @@ def analyze_class(self, defn: ClassDef) -> None:
11961196

11971197
# should this be memoized in TypeInfo?
11981198
def find_maximum_class_id(self, info: TypeInfo) -> int:
1199-
# top class?
1200-
if len(info.mro) in (0, 1):
1201-
return len(info.type_vars)
1202-
else:
1199+
if info.bases:
12031200
return len(info.type_vars) + max(
1204-
self.find_maximum_class_id(cls)
1205-
for cls in info.mro[1:]
1201+
self.find_maximum_class_id(cls.type)
1202+
for cls in info.bases
12061203
)
1204+
else:
1205+
return len(info.type_vars)
12071206

12081207
def is_core_builtin_class(self, defn: ClassDef) -> bool:
12091208
return self.cur_mod_id == 'builtins' and defn.name in CORE_BUILTIN_CLASSES

0 commit comments

Comments
 (0)