Refactor: simplify combine_function_signatures by reducing line count and preserving comments#19196
Open
victorletichevsky wants to merge 3 commits intopython:masterfrom
Conversation
…eserving original comments
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
sterliakov
reviewed
Jun 1, 2025
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), [] |
Collaborator
There was a problem hiding this comment.
This looks like a penalty to readability rather than refactoring, why merge two unrelated assignments?
mypy/checkexpr.py
Outdated
| 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)): |
Collaborator
There was a problem hiding this comment.
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], |
Collaborator
There was a problem hiding this comment.
This is definitely an improvement!
Contributor
|
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_signaturesmethod to reduce line count and eliminate redundancy, while preserving all original logic and explanatory comments.Key improvements:
Notes