Conversation

victorletichevsky

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:

  • Reduced vertical space and simplified control flow
  • Preserved all original comments, including the TODO
  • Kept behavior unchanged and all test cases passing

Notes

@github-actionsGitHub Actions

This comment has been minimized.

new_returns: list[Type] = []

new_args: list[list[Type]] = [[] for _ in callables[0].arg_types]
new_kinds, new_returns = list(callables[0].arg_kinds), []
Copy link
Collaborator

@sterliakov sterliakov Jun 1, 2025

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?

@@ -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)):
Copy link
Collaborator

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],
Copy link
Collaborator

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!

@github-actionsGitHub Actions

Diff from mypy_primer, showing the effect of this PR on open source code:

nox (https://.com/wntrblm/nox): 1.31x slower (30.9s -> 40.5s in single noisy sample)

typeshed-stats (https://.com/AlexWaygood/typeshed-stats): 1.55x slower (66.3s -> 102.5s in single noisy sample)

materialize (https://.com/MaterializeInc/materialize): 1.06x slower (135.9s -> 144.5s in single noisy sample)

imagehash (https://.com/JohannesBuchner/imagehash): 1.06x slower (74.0s -> 78.8s in single noisy sample)

discord.py (https://.com/Rapptz/discord.py): 1.10x slower (281.1s -> 308.0s in single noisy sample)

Sign up for free to join this conversation on . Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.