mirror of
https://github.com/home-assistant/core.git
synced 2025-08-11 16:45:19 +02:00
Add ability to check kwargs type annotation
This commit is contained in:
@@ -22,6 +22,7 @@ class TypeHintMatch:
|
|||||||
function_name: str
|
function_name: str
|
||||||
return_type: list[str] | str | None | object
|
return_type: list[str] | str | None | object
|
||||||
arg_types: dict[int, str] | None = None
|
arg_types: dict[int, str] | None = None
|
||||||
|
kwargs_type: str | None = None
|
||||||
check_return_type_inheritance: bool = False
|
check_return_type_inheritance: bool = False
|
||||||
|
|
||||||
|
|
||||||
@@ -613,7 +614,7 @@ class HassTypeHintChecker(BaseChecker): # type: ignore[misc]
|
|||||||
priority = -1
|
priority = -1
|
||||||
msgs = {
|
msgs = {
|
||||||
"W7431": (
|
"W7431": (
|
||||||
"Argument %d should be of type %s",
|
"Argument %s should be of type %s",
|
||||||
"hass-argument-type",
|
"hass-argument-type",
|
||||||
"Used when method argument type is incorrect",
|
"Used when method argument type is incorrect",
|
||||||
),
|
),
|
||||||
@@ -709,6 +710,16 @@ class HassTypeHintChecker(BaseChecker): # type: ignore[misc]
|
|||||||
args=(key + 1, expected_type),
|
args=(key + 1, expected_type),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check that kwargs is correctly annotated.
|
||||||
|
if match.kwargs_type and not _is_valid_type(
|
||||||
|
match.kwargs_type, node.args.kwargannotation
|
||||||
|
):
|
||||||
|
self.add_message(
|
||||||
|
"hass-argument-type",
|
||||||
|
node=node,
|
||||||
|
args=(node.args.kwarg, match.kwargs_type),
|
||||||
|
)
|
||||||
|
|
||||||
# Check the return type.
|
# Check the return type.
|
||||||
if not _is_valid_return_type(match, node.returns):
|
if not _is_valid_return_type(match, node.returns):
|
||||||
self.add_message(
|
self.add_message(
|
||||||
|
Reference in New Issue
Block a user