Ignore nested functions when enforcing type hints in tests (#118948)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user