Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-82129: Improve annotations for make_dataclass() #133406

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

Merged
merged 14 commits into from
May 5, 2025

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented May 4, 2025

Closes #82129. Closes #122262.

This is on top of @sobolevn's #122262 but jumps through a few more hoops to achieve these goals:

  • The annotations on dataclasses with make_dataclass() are sensible in all formats
  • We don't import typing until we really have to

@@ -868,7 +868,7 @@ def get_annotations(
# For FORWARDREF, we use __annotations__ if it exists
try:
ann = _get_dunder_annotations(obj)
except NameError:
except Exception:
Copy link
Member Author

Choose a reason for hiding this comment

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

I made a separate PR (with tests) for this change in #133407.

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

Thank you for reviving this PR! It looks like it achieves its main goal.

@JelleZijlstra JelleZijlstra marked this pull request as ready for review May 4, 2025 22:59
@JelleZijlstra JelleZijlstra requested a review from ericvsmith as a code owner May 4, 2025 22:59
@JelleZijlstra JelleZijlstra requested a review from sobolevn May 4, 2025 23:26
Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

LGTM

@JelleZijlstra JelleZijlstra merged commit bb5ec6e into python:main May 5, 2025
45 checks passed
@JelleZijlstra JelleZijlstra deleted the gh18219-alt branch May 5, 2025 15:21
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.

get_type_hints fails if there are un-annotated fields in a dataclass
2 participants