Skip to content

Added cls.__dict__.get('__annotations__') check #18233

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

dericcrago
Copy link

@dericcrago dericcrago commented May 20, 2025

Added cls.__dict__.get('__annotations__') check for Python 3.10+ and Python < 3.10 with typing-extensions enabled.

Closes #17853

Summary

Added cls.__dict__.get('__annotations__') check for Python 3.10+ and Python < 3.10 with typing-extensions enabled.

Test Plan

cargo test

@AlexWaygood AlexWaygood added the rule Implementing or modifying a lint rule label May 20, 2025
@AlexWaygood
Copy link
Member

AlexWaygood commented May 20, 2025

looks like you need to regenerate the JSON schema -- running cargo dev generate-all and committing the changes should fix it!

Python < 3.10 with `typing_extensions` enabled.
@dericcrago dericcrago force-pushed the 17853-cls-dict-annotations branch from 34602f5 to 8669fd7 Compare May 20, 2025 21:37
Copy link
Contributor

github-actions bot commented May 20, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dericcrago
Copy link
Author

Thank you for the review @JelleZijlstra! I will work on these changes.

Copy link
Contributor

@JelleZijlstra JelleZijlstra 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, thanks!

The error message might be a bit long with mentioning all the different get_annotations() functions.

#[derive_message_formats]
fn message(&self) -> String {
"Use `typing_extensions.get_annotations` (Python < 3.10 with \
`typing_extensions` enabled), `inspect.get_annotations` \
Copy link
Contributor

Choose a reason for hiding this comment

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

"enabled" is an odd word choice, is that used elsewhere in Ruff? I'd use "installed" (this also occurs a few other times in the file).

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for taking another look @JelleZijlstra!

You're right, the original error message was a bit lengthy. I've trimmed about 25 characters off, but I'm happy to iterate on this further if you have other suggestions for conciseness.

Regarding "enabled" vs. "installed"; thanks for pointing that out. I think some distinction and mixed use might be necessary. For example, I think that:

Does this distinction for using 'enabled' in the context of the ruff setting seem reasonable to you? I'm open to suggestions if you still feel like "installed" makes more sense or if a different term would be clearer here.

I've pushed the above changes for review.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, didn't realize that was a reference to a Ruff setting.

Copy link
Author

Choose a reason for hiding this comment

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

That's understandable, the code was a bit ambiguous regarding the typing-extensions module vs setting. I'm hopeful that the changes in the last commit make that distinction clearer. Please let me know if it's still not quite hitting the mark! Thanks for sticking with me @JelleZijlstra!

@MichaReiser MichaReiser requested a review from dylwil3 May 23, 2025 14:22
@MichaReiser
Copy link
Member

MichaReiser commented May 23, 2025

@dylwil3 could you review this PR (as the author of the issue and it being Python 3.14 related?)

@MichaReiser MichaReiser added the python314 Related to Python 3.14 label May 23, 2025
@ntBre ntBre self-requested a review May 30, 2025 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
python314 Related to Python 3.14 rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn users of Python 3.14+ against cls.__dict__.get("__annotations__", {})
4 participants