-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[WIP] Add more module_utils typing #11257
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
russoz
left a comment
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.
Other than the deco.py file, it LGTM. That one should be an exception, IMO.
| @t.overload | ||
| def check_mode_skip_returns( | ||
| callable: Callable[t.Concatenate[S, P], T], value: T | None = None | ||
| ) -> Callable[[Callable[t.Concatenate[S, P], T]], Callable[t.Concatenate[S, P], T]]: ... | ||
|
|
||
|
|
||
| @t.overload | ||
| def check_mode_skip_returns( | ||
| callable: None, value: T | ||
| ) -> Callable[[Callable[t.Concatenate[S, P], T]], Callable[t.Concatenate[S, P], T]]: ... | ||
|
|
||
|
|
||
| @t.overload | ||
| def check_mode_skip_returns( | ||
| callable: None = None, *, value: T | ||
| ) -> Callable[[Callable[t.Concatenate[S, P], T]], Callable[t.Concatenate[S, P], T]]: ... | ||
|
|
||
|
|
||
| def check_mode_skip_returns( | ||
| callable: Callable[t.Concatenate[S, P], T] | None = None, value: T | None = None | ||
| ) -> Callable[[Callable[t.Concatenate[S, P], T]], Callable[t.Concatenate[S, P], T]]: | ||
| def deco(func: Callable[t.Concatenate[S, P], T]) -> Callable[t.Concatenate[S, P], T]: |
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.
TBH, I think this is an example where life is better without the type hints. The code is now barely readable, just so that vscode, or pycharm, or copilot, or some other tool, can make a match with a caller. I'd rather choose the human over the machine for this.
Something is bothering me. I have been actually going over this file again and again, until it hit me: strongly-typed language feelings! This level of type hinting transform a "light", fun language as Python into something heavy and, pardon my language, a pain in the rear to code.
And even though the types are not enforced in runtime, if we enforce them at build time, the practical effect to the programmer is to work in a strongly-typed language. This gives me Java, C, C++ feelings.
Of course it is nice to have the tool tell you that this or that is the wrong type, but at what cost? Simple things like def f(a: int, b: str) are easy to read. These signatures above are, to an average reader (I include myself in that category), written in a different language that I need to translate into Python before I can understand what is happening.
I think this file is easier to work with without those type hints.
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.
TBH, I think this is an example where life is better without the type hints.
I strongly disagree here. Without the type hints, one should never use these decorators, as you will never get any type checks for the functions that are decorated.
I would rather suggest to stop using decorators, or sticking to simpler ones (which need less complex types), than not typing them.
I think this file is easier to work with without those type hints.
Only if we deprecate this file and stop using the decorators in it.
SUMMARY
This time I looked in module_utils' subdirectories :)
ISSUE TYPE
COMPONENT NAME
various module utils