Skip to content

Commit 87ef086

Browse files
committed
Address CR; add more comments
1 parent 0edd113 commit 87ef086

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

mypy/server/update.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,8 @@ def key(node: FineGrainedDeferredNode) -> int:
10251025
# We seem to need additional passes in fine-grained incremental mode.
10261026
checker.pass_num = 0
10271027
checker.last_pass = 3
1028+
# It is tricky to reliably invalidate constructor cache in fine-grained increments.
1029+
# See PR 19514 description for details.
10281030
more = checker.check_second_pass(nodes, allow_constructor_cache=False)
10291031
while more:
10301032
more = False

mypy/typeops.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,15 @@ def type_object_type(info: TypeInfo, named_type: Callable[[str], Instance]) -> P
177177
init_index = info.mro.index(init_method.node.info)
178178
new_index = info.mro.index(new_method.node.info)
179179

180-
if checker_state.type_checker:
181-
builtins_type = checker_state.type_checker.named_type("builtins.type")
180+
if info.metaclass_type is not None:
181+
fallback = info.metaclass_type
182+
elif checker_state.type_checker:
183+
# Prefer direct call when it is available. It is faster, and,
184+
# unfortunately, some callers provide bogus callback.
185+
fallback = checker_state.type_checker.named_type("builtins.type")
182186
else:
183-
builtins_type = named_type("builtins.type")
187+
fallback = named_type("builtins.type")
184188

185-
fallback = info.metaclass_type or builtins_type
186189
if init_index < new_index:
187190
method: FuncBase | Decorator = init_method.node
188191
is_new = False
@@ -218,6 +221,8 @@ def type_object_type(info: TypeInfo, named_type: Callable[[str], Instance]) -> P
218221
# return type and insert type arguments.
219222
if isinstance(method, FuncBase):
220223
if isinstance(method, OverloadedFuncDef) and not method.type:
224+
# Do not cache if the type is not ready. Same logic for decorators is
225+
# achieved in early return above because is_valid_constructor() is False.
221226
allow_cache = False
222227
t = function_type(method, fallback)
223228
else:

0 commit comments

Comments
 (0)