Improve error message for incompatible **kwargs argument#21129
Open
yourlocaljosh wants to merge 2 commits intopython:masterfrom
Open
Improve error message for incompatible **kwargs argument#21129yourlocaljosh wants to merge 2 commits intopython:masterfrom
yourlocaljosh wants to merge 2 commits intopython:masterfrom
Conversation
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: pyinstrument (https://github.com/joerick/pyinstrument)
+ pyinstrument/context_manager.py:40: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ pyinstrument/context_manager.py:63: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
prefect (https://github.com/PrefectHQ/prefect)
+ src/prefect/deployments/runner.py:870: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ src/prefect/tasks.py:2255: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ src/prefect/cli/deploy/_schedules.py:70: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
colour (https://github.com/colour-science/colour)
+ colour/plotting/volume.py:785: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ colour/plotting/phenomena.py:1323: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ colour/plotting/phenomena.py:1370: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ colour/plotting/phenomena.py:1482: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ colour/plotting/phenomena.py:1538: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ colour/plotting/models.py:1984: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ colour/plotting/models.py:1988: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ colour/io/luts/tests/test_lut.py:521: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ colour/examples/contrast/examples_contrast.py:104: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/wrapper/_implementations.py:446: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
discord.py (https://github.com/Rapptz/discord.py)
+ discord/http.py:806: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ discord/client.py:727: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ discord/ext/commands/context.py:1141: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
ibis (https://github.com/ibis-project/ibis)
+ ibis/expr/types/temporal.py:1086: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
jax (https://github.com/google/jax)
+ jax/_src/xla_bridge.py:190: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ jax/_src/pallas/helpers.py:263: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ jax/_src/pallas/helpers.py:265: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ jax/_src/pallas/einshape.py:330: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ jax/_src/pallas/einshape.py:368: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
scipy (https://github.com/scipy/scipy)
+ scipy/fftpack/tests/gen_fftw_ref.py:43: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ scipy/fftpack/tests/gen_fftw_ref.py:59: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ scipy/fftpack/tests/gen_fftw_ref.py:74: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
apprise (https://github.com/caronc/apprise)
+ apprise/plugins/xmpp/base.py:422: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ apprise/plugins/xmpp/base.py:425: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
artigraph (https://github.com/artigraph/artigraph)
+ tests/arti/types/test_types.py:146: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
+ tests/arti/types/test_types.py:150: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
pyppeteer (https://github.com/pyppeteer/pyppeteer)
+ pyppeteer/launcher.py:149: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8874
When a function is called with
**kwargswhose value types areincompatible with the expected parameter types, mypy produced
multiple confusing errors with no actionable guidance. This PR
adds a note suggesting the user annotate the
**argument as**kwargs: Anyor use a TypedDict for more precise typing.Before:
test.py:4: error: Argument 1 to "f" has incompatible type "**dict[str, int]"; expected "str"
After:
test.py:4: error: Argument 1 to "f" has incompatible type "**dict[str, int]"; expected "str"
test.py:4: note: Consider annotating the ** argument as "**kwargs: Any" or using a TypedDict
Notes:
**kwargs: Anyannotation syntax rather thanDict[str, Any]since that's what a user would actually write in their function
signature.
check-kwargs.test. I updated existing tests across 8test files to reflect the new note.