-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ruff] Implement union-with-annotated-type (RUF066) #21079
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
base: main
Are you sure you want to change the base?
Conversation
|
I think this rule makes sense to me (catching I do think we should come up with a less cryptic name :). We certainly can't use the nested terminology because the annotated documentation uses that to refer to
Maybe something like |
|
I agree that it's a useful rule — I'm not aware of any case where you would want to use an For names I prefer |
5fe2042 to
cfe1801
Compare
| def f3(z: Optional[Annotated[float, "A float"]]) -> None: | ||
| pass | ||
|
|
||
| e: Annotated[Annotated[int, "An integer"], "Another annotation"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This being an error implies that list[Annotated[...]] or similar would also produce an error. That part seems fine to me, but I wonder if it would be worth having a separate error message for these cases since the mention of union/optional doesn't make sense here? Would also like to have test cases showing that behavior one way or the other.
| /// ``` | ||
| /// | ||
| #[derive(ViolationMetadata)] | ||
| #[violation_metadata(preview_since = "0.14.4")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a bump as well 😅
Summary
This PR implements a new rule, nested-annotated-type, as discussed in #21037 . This rule fails for type definitions including
Annotatednested within some other type.Test Plan
New snapshosts in
RUF066.pywithcargo insta test.