-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add Y062: Forbid duplicates in Literal[]
slices
#449
Conversation
Literal[]
slices
This comment has been minimized.
This comment has been minimized.
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 looks great; I really like the way you put it together :)
This comment has been minimized.
This comment has been minimized.
Wow that's a hell of a review 😮 Thanks for the taking the time to write it all up! I had hunch the py38 fails would have something to do with the AST changes but wasn't sure so that cleared that up :) I ended up removing the offending doctest (agreed that it's probably not worth to try to fix it) and applied your suggestion to suppress Y061 when we emit Y062. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
From my side, this should be gtg ;) |
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.
Nearly there! Left a smattering of minor suggestions :D
Co-authored-by: Alex Waygood <[email protected]>
Applied! The test cases are much better with an actual explanation |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Alex Waygood <[email protected]>
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.
LGTM. Thanks! :D
This change has no effect on typeshed. 🤖🎉 |
Minutes after merging, I realised that we give completely incomprehensible suggestions for something like this: from typing import Literal
x: Literal[None] | Literal[None, True] Output from linting this:
I don't think it's a massive issue, though, as this is a real edge case. Definitely not worth fixing if it would mean significantly complicating our code |
Oh damn why are there some many edge cases every time.. 😆 But yeah, as you say, this one seems very uncommon so I'd leave it as is. If it becomes an issue later, we can revisit this.. |
Previous discussion for context: #435 (comment)
Example:
Literal[True, True, False, False]
- emits Y062 for bothTrue
andFalse
.This is how the new rule interacts with Y061:
Literal[None]
,Literal[None, None]
, etc.. - Only Y061 is emitted and the suggestion is always justNone
(previouslyLiteral[None, None]
would suggestLiteral[] | None
)None
and other duplicates e.g.Literal[None, True, True]
- emits Y061, which suggestsLiteral[True, True] | None
, and a separate Y062. The Y061 suggestion is not entirely correct though. In theory we could provide a better one (i.e.Literal[True] | None
) but I'm not sure if we should, given that we emit a separate Y062 as well.. Thoughts?