Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve accuracy of dataclasses.Field #12082

Merged
merged 5 commits into from
Jun 24, 2024

Conversation

max-muoto
Copy link
Contributor

Account for deferred annotations (str), and other objects such as unions (Any).

Fixes: #11268

@max-muoto max-muoto changed the title Improve accuracy of dataclasses.Field Improve accuracy of dataclasses.Field Jun 2, 2024

This comment has been minimized.

@max-muoto
Copy link
Contributor Author

@JelleZijlstra Do you maybe want to take a look here?

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Jun 7, 2024

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

mitmproxy (https://github.com/mitmproxy/mitmproxy)
+ mitmproxy/coretypes/serializable.py:85: error: Argument 2 to "_to_state" has incompatible type "type[Any] | str | Any"; expected "type[Any]"  [arg-type]
+ mitmproxy/coretypes/serializable.py:92: error: Argument 2 to "_to_val" has incompatible type "type[Any] | str | Any"; expected "type[Any]"  [arg-type]
+ mitmproxy/coretypes/serializable.py:108: error: Argument 2 to "_to_val" has incompatible type "type[Any] | str | Any"; expected "type[Any]"  [arg-type]

kornia (https://github.com/kornia/kornia)
+ kornia/utils/helpers.py:349: error: Argument 2 to "dict_to_dataclass" has incompatible type "type[Any] | str | Any"; expected "type[Any]"  [arg-type]

mkosi (https://github.com/systemd/mkosi)
+ mkosi/config.py:4242:41: error: Argument 2 has incompatible type "Union[type[Any], str, Any]"; expected "type"  [arg-type]

@max-muoto
Copy link
Contributor Author

@JelleZijlstra or @srittau Wanted to follow-up here.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Thanks!

@srittau srittau merged commit 6b2033a into python:main Jun 24, 2024
63 checks passed
max-muoto added a commit to max-muoto/typeshed that referenced this pull request Sep 8, 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.

dataclasses.Field.type isn't always a type
2 participants