python / typeshed

Collection of library stubs for Python, with static types
Other
4.3k stars 1.73k forks source link

Should flake8-pyi rule `Y051` be disabled? #12500

Closed gilbertbw closed 1 month ago

gilbertbw commented 1 month ago

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#L2156

This is failing the Y051 flake-pyi rule:

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?

gilbertbw commented 1 month ago

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.

gilbertbw commented 1 month ago

I should have linked to it: https://github.com/python/typeshed/blob/e9b3b03764d0557e103e1b2c4d95ce02965db22b/stubs/docutils/docutils/parsers/rst/directives/__init__.pyi#L33