Skip to content

Give type annotation suggestion for incompatible **kwargs error#3

Open
andyxzhu wants to merge 6 commits intomasterfrom
kwargs_message
Open

Give type annotation suggestion for incompatible **kwargs error#3
andyxzhu wants to merge 6 commits intomasterfrom
kwargs_message

Conversation

@andyxzhu
Copy link
Collaborator

Fixes python#8874.

When raising an error involving passing **kwargs, this PR adds a note informing the user of a potential fix based on @JukkaL's suggestion. For example,

main:3: error: Argument 2 to "dumps" has incompatible type "**Dict[str, int]"; expected "bool"
main:3: note: Consider using a TypedDict type or "Dict[str, any]" for the ** argument

Modified testing suite for compatibility with added note. Also created two new test cases based on JSON and Python classes .

@andyxzhu andyxzhu requested review from angelawuuu and kr321 April 28, 2024 09:19
@github-actions
Copy link

Diff from mypy_primer, showing the effect of this PR on open source code:

pyppeteer (https://github.com/pyppeteer/pyppeteer)
+ pyppeteer/launcher.py:149: note: Consider using a TypedDict type or "Dict[str, any]" for the ** argument

discord.py (https://github.com/Rapptz/discord.py)
+ discord/http.py:544: note: Consider using a TypedDict type or "Dict[str, any]" for the ** argument
+ discord/client.py:658: note: Consider using a TypedDict type or "Dict[str, any]" for the ** argument

ibis (https://github.com/ibis-project/ibis)
+ ibis/expr/types/temporal.py:659: note: Consider using a TypedDict type or "Dict[str, any]" for the ** argument

hydra-zen (https://github.com/mit-ll-responsible-ai/hydra-zen)
+ src/hydra_zen/structured_configs/_implementations.py:1129: note: Consider using a TypedDict type or "Dict[str, any]" for the ** argument
+ src/hydra_zen/wrapper/_implementations.py:454: note: Consider using a TypedDict type or "Dict[str, any]" for the ** argument

Copy link
Collaborator

@angelawuuu angelawuuu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Owner

@kr321 kr321 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@andyxzhu andyxzhu changed the title Kwargs message Give type annotation suggestion for incompatible **kwargs error Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Generate better error message for incompatible **kwargs

4 participants