Y051 detects redundant unions between Literal types and builtin supertypes. For example, Literal[5] is redundant in the union int | Literal[5], and Literal[True] is redundant in the union Literal[True] | bool.
But on the basis that these typings are not just used for type checking, but also to e.g. drive intellisense I think we should be able to add these unions. I suspect there are other parts of the stdlib that have this sort of parameter API?
Doing a bit more digging I found a case where this rule is suppressed. I will do the same in my PR, I can see the benefit it supressing this rule where required to at least draw the reviewers attention to it.
Hello,
I have been getting started with
tkinter
this week, and noticed some issues/possible improvements to the type hints. One of these is adding hints for a string param that can technically be anything, but in practice is always one of a few options: https://github.com/python/typeshed/blob/7874433064e35ddd87f8f5f68f671a6cd3ae654c/stdlib/tkinter/__init__.pyi#L2156This is failing the Y051 flake-pyi rule:
But on the basis that these typings are not just used for type checking, but also to e.g. drive intellisense I think we should be able to add these unions. I suspect there are other parts of the stdlib that have this sort of parameter API?