Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,26 +846,51 @@ def get_additional_deps(self, file: MypyFile) -> list[tuple[int, str, int]]:
return deps

def get_type_analyze_hook(self, fullname: str) -> Callable[[AnalyzeTypeContext], Type] | None:
return self._find_hook(lambda plugin: plugin.get_type_analyze_hook(fullname))
# Micro-optimization: Inline iteration over plugins
for plugin in self._plugins:
hook = plugin.get_type_analyze_hook(fullname)
if hook is not None:
return hook
return None

def get_function_signature_hook(
self, fullname: str
) -> Callable[[FunctionSigContext], FunctionLike] | None:
return self._find_hook(lambda plugin: plugin.get_function_signature_hook(fullname))
# Micro-optimization: Inline iteration over plugins
for plugin in self._plugins:
hook = plugin.get_function_signature_hook(fullname)
if hook is not None:
return hook
return None

def get_function_hook(self, fullname: str) -> Callable[[FunctionContext], Type] | None:
return self._find_hook(lambda plugin: plugin.get_function_hook(fullname))

def get_method_signature_hook(
self, fullname: str
) -> Callable[[MethodSigContext], FunctionLike] | None:
return self._find_hook(lambda plugin: plugin.get_method_signature_hook(fullname))
# Micro-optimization: Inline iteration over plugins
for plugin in self._plugins:
hook = plugin.get_method_signature_hook(fullname)
if hook is not None:
return hook
return None

def get_method_hook(self, fullname: str) -> Callable[[MethodContext], Type] | None:
return self._find_hook(lambda plugin: plugin.get_method_hook(fullname))
# Micro-optimization: Inline iteration over plugins
for plugin in self._plugins:
hook = plugin.get_method_hook(fullname)
if hook is not None:
return hook
return None

def get_attribute_hook(self, fullname: str) -> Callable[[AttributeContext], Type] | None:
return self._find_hook(lambda plugin: plugin.get_attribute_hook(fullname))
# Micro-optimization: Inline iteration over plugins
for plugin in self._plugins:
hook = plugin.get_attribute_hook(fullname)
if hook is not None:
return hook
return None

def get_class_attribute_hook(self, fullname: str) -> Callable[[AttributeContext], Type] | None:
return self._find_hook(lambda plugin: plugin.get_class_attribute_hook(fullname))
Expand Down Expand Up @@ -897,6 +922,6 @@ def get_dynamic_class_hook(
def _find_hook(self, lookup: Callable[[Plugin], T]) -> T | None:
for plugin in self._plugins:
hook = lookup(plugin)
if hook:
if hook is not None:
return hook
return None