Remove replicated async definitions in pylint plugin (#73823)
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
This commit is contained in:
parent
aef69f87f4
commit
b17d4ac65c
1 changed files with 22 additions and 73 deletions
|
@ -28,6 +28,15 @@ class TypeHintMatch:
|
|||
kwargs_type: str | None = None
|
||||
"""kwargs_type is for the special case `**kwargs`"""
|
||||
check_return_type_inheritance: bool = False
|
||||
has_async_counterpart: bool = False
|
||||
|
||||
def need_to_check_function(self, node: nodes.FunctionDef) -> bool:
|
||||
"""Confirm if function should be checked."""
|
||||
return (
|
||||
self.function_name == node.name
|
||||
or self.has_async_counterpart
|
||||
and node.name == f"async_{self.function_name}"
|
||||
)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -60,14 +69,7 @@ _FUNCTION_MATCH: dict[str, list[TypeHintMatch]] = {
|
|||
1: "ConfigType",
|
||||
},
|
||||
return_type="bool",
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_setup",
|
||||
arg_types={
|
||||
0: "HomeAssistant",
|
||||
1: "ConfigType",
|
||||
},
|
||||
return_type="bool",
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_setup_entry",
|
||||
|
@ -121,16 +123,7 @@ _FUNCTION_MATCH: dict[str, list[TypeHintMatch]] = {
|
|||
3: "DiscoveryInfoType | None",
|
||||
},
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_setup_platform",
|
||||
arg_types={
|
||||
0: "HomeAssistant",
|
||||
1: "ConfigType",
|
||||
2: "AddEntitiesCallback",
|
||||
3: "DiscoveryInfoType | None",
|
||||
},
|
||||
return_type=None,
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_setup_entry",
|
||||
|
@ -314,14 +307,7 @@ _FUNCTION_MATCH: dict[str, list[TypeHintMatch]] = {
|
|||
1: "ConfigType",
|
||||
},
|
||||
return_type=["DeviceScanner", "DeviceScanner | None"],
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_get_scanner",
|
||||
arg_types={
|
||||
0: "HomeAssistant",
|
||||
1: "ConfigType",
|
||||
},
|
||||
return_type=["DeviceScanner", "DeviceScanner | None"],
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
],
|
||||
"device_trigger": [
|
||||
|
@ -498,31 +484,19 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
|||
function_name="set_percentage",
|
||||
arg_types={1: "int"},
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_set_percentage",
|
||||
arg_types={1: "int"},
|
||||
return_type=None,
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="set_preset_mode",
|
||||
arg_types={1: "str"},
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_set_preset_mode",
|
||||
arg_types={1: "str"},
|
||||
return_type=None,
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="set_direction",
|
||||
arg_types={1: "str"},
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_set_direction",
|
||||
arg_types={1: "str"},
|
||||
return_type=None,
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="turn_on",
|
||||
|
@ -532,25 +506,13 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
|||
},
|
||||
kwargs_type="Any",
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_turn_on",
|
||||
named_arg_types={
|
||||
"percentage": "int | None",
|
||||
"preset_mode": "str | None",
|
||||
},
|
||||
kwargs_type="Any",
|
||||
return_type=None,
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="oscillate",
|
||||
arg_types={1: "bool"},
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_oscillate",
|
||||
arg_types={1: "bool"},
|
||||
return_type=None,
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -587,31 +549,19 @@ _INHERITANCE_MATCH: dict[str, list[ClassTypeHintMatch]] = {
|
|||
function_name="lock",
|
||||
kwargs_type="Any",
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_lock",
|
||||
kwargs_type="Any",
|
||||
return_type=None,
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="unlock",
|
||||
kwargs_type="Any",
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_unlock",
|
||||
kwargs_type="Any",
|
||||
return_type=None,
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="open",
|
||||
kwargs_type="Any",
|
||||
return_type=None,
|
||||
),
|
||||
TypeHintMatch(
|
||||
function_name="async_open",
|
||||
kwargs_type="Any",
|
||||
return_type=None,
|
||||
has_async_counterpart=True,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
@ -831,14 +781,13 @@ class HassTypeHintChecker(BaseChecker): # type: ignore[misc]
|
|||
) -> None:
|
||||
for match in matches:
|
||||
for function_node in node.mymethods():
|
||||
function_name: str | None = function_node.name
|
||||
if match.function_name == function_name:
|
||||
if match.need_to_check_function(function_node):
|
||||
self._check_function(function_node, match)
|
||||
|
||||
def visit_functiondef(self, node: nodes.FunctionDef) -> None:
|
||||
"""Called when a FunctionDef node is visited."""
|
||||
for match in self._function_matchers:
|
||||
if node.name != match.function_name or node.is_method():
|
||||
if not match.need_to_check_function(node) or node.is_method():
|
||||
continue
|
||||
self._check_function(node, match)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue