Skip to content

[mypyc] Optimize type(x) and x.__class__ #19691

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

Merged
merged 1 commit into from
Aug 19, 2025
Merged

[mypyc] Optimize type(x) and x.__class__ #19691

merged 1 commit into from
Aug 19, 2025

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Aug 19, 2025

Using Py_TYPE avoids a function call. Also specialize x.__class__ for instances of native classes -- it's treated as equivalent to type(x). This is not generally possible, so only do it for native instances where we can make more assumptions.

Using `Py_TYPE` avoids a function call. Also specialize `x.__class__`
for instances of native classes -- it's treated as equivalent to
`type(x)`.  This is not generally possible, so only do it for native
instances where we can make more assumptions.
@JukkaL JukkaL merged commit 722f4dd into master Aug 19, 2025
13 checks passed
@JukkaL JukkaL deleted the mypyc-type branch August 19, 2025 15:33
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