Do not use dictionary in CallableType#19580
Merged
ilevkivskyi merged 3 commits intopython:masterfrom Aug 4, 2025
Merged
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Member
Author
|
Oh, hm, this uncovers an inconsistency in how we format constructors, depending on whether they are decorated or not. IMO def [T] list(self) -> list[T]looks better than def [T] __init__(self) -> list[T]I will see how many tests needs updating to converge on this option, and if not too many, I am going to do it in this PR. |
Member
Author
|
Yeah, no, 15 tests need to be updated, this will also probably cause some noisy |
Contributor
|
Diff from mypy_primer, showing the effect of this PR on open source code: pydantic (https://github.com/pydantic/pydantic)
- pydantic/v1/validators.py:615: note: def NamedTuple(self, str, Iterable[tuple[str, Any]], /) -> NamedTupleT
+ pydantic/v1/validators.py:615: note: def __init__(self, str, Iterable[tuple[str, Any]], /) -> NamedTupleT
- pydantic/v1/validators.py:615: note: def NamedTuple(self, str, None = ..., /, **kwargs: Any) -> NamedTupleT
+ pydantic/v1/validators.py:615: note: def __init__(self, str, None = ..., /, **kwargs: Any) -> NamedTupleT
|
sterliakov
approved these changes
Aug 4, 2025
Collaborator
sterliakov
left a comment
There was a problem hiding this comment.
LG, thanks! I personally prefer def __init__(...) by a huge margin - def ClassName(...) looks confusing, trying to untangle the latter always takes me a few extra seconds.
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 is mypyc-specific optimization:
dictcreation is quite slow, so we should not create a dict in theCallableTypeconstructor. Instead, I store the required info on the relevantFuncDefobject (and restore the link to definition infixup.py). Quite surprisingly, this gives 2% speedup on my desktop.