-
Notifications
You must be signed in to change notification settings - Fork 109
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
New check: duplicate types in type hint, or duplicate literals in set #371
Comments
This seems super uncontroversial if we can AST parse this out nicely covering the edge cases you've outlined and we can improve on reports ... I'd be happy to add this. We can run this over some large type checked repos before releasing too to be extra safe. |
FYI we already have a check for duplicate items in a union over at flake8-pyi (error code Y016). But we only support Our tests for Y016 are here, along with our tests for our various other union-related lints: https://github.com/PyCQA/flake8-pyi/blob/main/tests/union_duplicates.pyi |
I think these should be two different checks, but I'm happy to work on a duplicate items in a set check.
What do you mean by checking I'm not entirely sure how common these would be, and it would increase the complexity of the check, but I could be missing another syntax here! |
oops, I misremembered and thought one could write |
I'm supportive of doing this for sets and also for dict keys, where it's likely to mean the code silently does something different from what the user wants. Less sure about the other examples brought up here. |
these should pretty much always be typos and/or bad copy-pastes, with very few to no false alarms. Don't think it's super common, but definitely not rare or super esoteric.
The check shouldn't have to be too complicated to implement, for the type hint probably need a whitelist of what types you look in (List/list, Set/set, Dict/dict (with special logic), OrderedDict, Optional, Union, Literal...).
For sets you only need to look inside
set()
(ast.Call) and inside{}
(ast.Set), and probably only include literal int/float/strings.The text was updated successfully, but these errors were encountered: