Skip to content

Commit 6f7d716

Browse files
authored
Speed up the default plugin (#19462)
Use precalculated set objects in more places. This is similar to #19385. Some cases were still unoptimized. I used trace logging (#19457) to identify functions where we were creating many set objects, and I noticed that these were unnecessary. This is a part of a set of micro-optimizations that improve self check performance by ~5.5%.
1 parent edd491f commit 6f7d716

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mypy/plugins/default.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282

8383
TD_SETDEFAULT_NAMES: Final = {n + ".setdefault" for n in TPDICT_FB_NAMES}
8484
TD_POP_NAMES: Final = {n + ".pop" for n in TPDICT_FB_NAMES}
85+
TD_DELITEM_NAMES: Final = {n + ".__delitem__" for n in TPDICT_FB_NAMES}
8586

8687
TD_UPDATE_METHOD_NAMES: Final = (
8788
{n + ".update" for n in TPDICT_FB_NAMES}
@@ -144,11 +145,11 @@ def get_method_hook(self, fullname: str) -> Callable[[MethodContext], Type] | No
144145
return int_pos_callback
145146
elif fullname in ("builtins.tuple.__mul__", "builtins.tuple.__rmul__"):
146147
return tuple_mul_callback
147-
elif fullname in {n + ".setdefault" for n in TPDICT_FB_NAMES}:
148+
elif fullname in TD_SETDEFAULT_NAMES:
148149
return typed_dict_setdefault_callback
149-
elif fullname in {n + ".pop" for n in TPDICT_FB_NAMES}:
150+
elif fullname in TD_POP_NAMES:
150151
return typed_dict_pop_callback
151-
elif fullname in {n + ".__delitem__" for n in TPDICT_FB_NAMES}:
152+
elif fullname in TD_DELITEM_NAMES:
152153
return typed_dict_delitem_callback
153154
elif fullname == "_ctypes.Array.__getitem__":
154155
return array_getitem_callback

0 commit comments

Comments
 (0)