-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Refactor: simplify combine_function_signatures by reducing line count and preserving comments #19196
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: master
Are you sure you want to change the base?
Conversation
…eserving original comments
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
mypy/checkexpr.py
Outdated
new_returns: list[Type] = [] | ||
|
||
new_args: list[list[Type]] = [[] for _ in callables[0].arg_types] | ||
new_kinds, new_returns = list(callables[0].arg_kinds), [] |
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 like a penalty to readability rather than refactoring, why merge two unrelated assignments?
mypy/checkexpr.py
Outdated
@@ -3160,18 +3160,16 @@ def combine_function_signatures(self, types: list[ProperType]) -> AnyType | Call | |||
if len(new_kinds) != len(target.arg_kinds): | |||
too_complex = True | |||
break | |||
for i, (new_kind, target_kind) in enumerate(zip(new_kinds, target.arg_kinds)): | |||
if new_kind == target_kind: | |||
for i, (k1, k2) in enumerate(zip(new_kinds, target.arg_kinds)): |
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.
I think new_
and target_
prefixes are much clearer than k1
and k2
...
return callables[0].copy_modified( | ||
arg_types=final_args, | ||
arg_types=[make_simplified_union(args) for args in new_args], |
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 is definitely an improvement!
Diff from mypy_primer, showing the effect of this PR on open source code: nox (https://github.com/wntrblm/nox): 1.31x slower (30.9s -> 40.5s in single noisy sample)
typeshed-stats (https://github.com/AlexWaygood/typeshed-stats): 1.55x slower (66.3s -> 102.5s in single noisy sample)
materialize (https://github.com/MaterializeInc/materialize): 1.06x slower (135.9s -> 144.5s in single noisy sample)
imagehash (https://github.com/JohannesBuchner/imagehash): 1.06x slower (74.0s -> 78.8s in single noisy sample)
discord.py (https://github.com/Rapptz/discord.py): 1.10x slower (281.1s -> 308.0s in single noisy sample)
|
This pull request contributes to issue #5917, which encourages the decomposition and simplification of overly long methods to improve code clarity and maintainability.
Summary of changes
Refactored the
combine_function_signatures
method to reduce line count and eliminate redundancy, while preserving all original logic and explanatory comments.Key improvements:
Notes