Skip to content

Do not use dictionary in CallableType #19580

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ilevkivskyi
Copy link
Member

This is mypyc-specific optimization: dict creation is quite slow, so we should not create a dict in the CallableType constructor. Instead, I store the required info on the relevant FuncDef object (and restore the link to definition in fixup.py). Quite surprisingly, this gives 2% speedup on my desktop.

This comment has been minimized.

This comment has been minimized.

@ilevkivskyi
Copy link
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.

@ilevkivskyi
Copy link
Member Author

Yeah, no, 15 tests need to be updated, this will also probably cause some noisy mypy_primer, so better to do in a separate PR. (Also maybe others have a different idea on which way looks better)

Copy link
Contributor

github-actions bot commented Aug 4, 2025

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

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.

1 participant