Skip to content

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Aug 31, 2025

Several mypy micro-optimizations. Together with batches 2 and 3 these improve self check performance by 1.8%.

Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@hauntsaninja hauntsaninja merged commit 87f4dc8 into master Aug 31, 2025
20 checks passed
@hauntsaninja hauntsaninja deleted the mypy-opts-1 branch August 31, 2025 22:36
Comment on lines -2126 to +2128
self.variables = variables
self.variables: tuple[TypeVarLikeType, ...]
if variables is None:
self.variables = ()
else:
self.variables = tuple(variables)
Copy link
Collaborator

@cdce8p cdce8p Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, this does crash the pydantic.v1 extension.

 File "/.../python3.13/site-packages/pydantic/v1/mypy.py", line 868, in add_method signature.variables = [tvar_def] ^^^^^^^^^^^^^^^^^^^ TypeError: tuple object expected; got list

https://github.com/pydantic/pydantic/blob/v2.11.7/pydantic/v1/mypy.py#L866-L868

It can fairly easily be fixed and I'll open a PR for it soon. However, that might not be the only plugin which depends on it being "just" a sequence.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have evidence that this impacts multiple plugins, we can consider reverting this change.

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

Labels

None yet

3 participants