Ignore nested functions when enforcing type hints in tests (#118948)

This commit is contained in:
epenet
2024-06-06 10:43:31 +02:00
committed by GitHub
parent 093e85d59a
commit 7eda8aafc8
2 changed files with 26 additions and 4 deletions

View File

@@ -3138,15 +3138,15 @@ class HassTypeHintChecker(BaseChecker):
_class_matchers: list[ClassTypeHintMatch]
_function_matchers: list[TypeHintMatch]
_module_name: str
_module_node: nodes.Module
_in_test_module: bool
def visit_module(self, node: nodes.Module) -> None:
"""Populate matchers for a Module node."""
self._class_matchers = []
self._function_matchers = []
self._module_name = node.name
self._in_test_module = self._module_name.startswith("tests.")
self._module_node = node
self._in_test_module = node.name.startswith("tests.")
if (
self._in_test_module
@@ -3230,7 +3230,7 @@ class HassTypeHintChecker(BaseChecker):
if node.is_method():
matchers = _METHOD_MATCH
else:
if self._in_test_module:
if self._in_test_module and node.parent is self._module_node:
if node.name.startswith("test_"):
self._check_test_function(node, False)
return