You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This seems superficially related to other kwargs issues, but from what I've read those mostly related to annotating a function so that its signature matches another function. I want to annotate a dictionary so that it's type is whatever is allowed as kwargs to a particular function (or even better, if mypy can simply handle the case where a dictionary d is created and then immediately passed into a function with ** with nothing in between).
In order to improve our log messages without being redundant. We were surprised that mypy is no longer useful for checking that the arguments we pass in match the parameters that LambdaClient.invoke expects.
Is there a (non-redundant) way to type hint params such that mypy doesn't give me errors, but if a key is added to params dict which would be illegal to pass to LambdaClient.invoke then it is caught by mypy? I assume that if its possible at all, I would need something like TypeOf[LambdaClient.invoke].
Currently I get the following output from mypy post-refactor:
mypy mypy_test.py
mypy_test.py:13: error: Argument 1 to "invoke" of "LambdaClient" has incompatible type "**Dict[str, str]"; expected "Union[Literal['Event'], Literal['RequestResponse'], Literal['DryRun'], None]"
mypy_test.py:13: error: Argument 1 to "invoke" of "LambdaClient" has incompatible type "**Dict[str, str]"; expected "Union[Literal['None'], Literal['Tail'], None]"
mypy_test.py:13: error: Argument 1 to "invoke" of "LambdaClient" has incompatible type "**Dict[str, str]"; expected "Union[bytes, IO[Any], None]"
Found 3 errors in 1 file (checked 1 source file)
To get mypy to validate the call to invoke I need to do something very redundant like:
I did also try annotating params with Final to help mypy understand that it would not change between declaration and the invocation, however that did not change the type checking result.
The text was updated successfully, but these errors were encountered:
I realized Final is a useless annotation. It means variable will not be rebound, but doesn't indicate the dictionary won't be updated.
I tried using frozendict but that just complained about not finding stubs. I also tried annotating with TypedDict directly (hoping for some inference) but mypy claims that's not legal either.
This seems superficially related to other kwargs issues, but from what I've read those mostly related to annotating a function so that its signature matches another function. I want to annotate a dictionary so that it's type is whatever is allowed as
kwargs
to a particular function (or even better, if mypy can simply handle the case where a dictionaryd
is created and then immediately passed into a function with**
with nothing in between).We recently refactored
to
In order to improve our log messages without being redundant. We were surprised that
mypy
is no longer useful for checking that the arguments we pass in match the parameters thatLambdaClient.invoke
expects.Is there a (non-redundant) way to type hint
params
such that mypy doesn't give me errors, but if a key is added toparams
dict which would be illegal to pass toLambdaClient.invoke
then it is caught bymypy
? I assume that if its possible at all, I would need something likeTypeOf[LambdaClient.invoke]
.Currently I get the following output from
mypy
post-refactor:To get mypy to validate the call to
invoke
I need to do something very redundant like:I did also try annotating
params
withFinal
to helpmypy
understand that it would not change between declaration and the invocation, however that did not change the type checking result.The text was updated successfully, but these errors were encountered: