Skip to content

Conversation

@victorletichevsky
Copy link

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-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?

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-actions
Copy link
Contributor

github-actions bot commented Jun 1, 2025

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)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants