-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Mypy micro-optimizations (batch 1/3) #19768
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
Conversation
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
self.variables = variables | ||
self.variables: tuple[TypeVarLikeType, ...] | ||
if variables is None: | ||
self.variables = () | ||
else: | ||
self.variables = tuple(variables) |
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.
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.
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.
If we have evidence that this impacts multiple plugins, we can consider reverting this change.
Several mypy micro-optimizations. Together with batches 2 and 3 these improve self check performance by 1.8%.