Skip to content
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

[mypyc] Optimize int()/float()/complex() on native classes #14450

Conversation

ichard26
Copy link
Collaborator

int() and float() calls on native classes can simply call the associated dunder if the RInstance defines it, no need to load the type and call it.

bool() calls were already optimized merely a few days ago, but there wasn't an IRbuild test verifying this so I added one.


Follow up to #14422. I saw the PR and it reminded me that I had this old patch laying around :)

int() and float() calls on native classes can simply call the associated
dunder if the RInstance defines it, no need to load the type and call it.

bool() calls were already optimized merely a few days ago, but there
wasn't an IRbuild test verifying this so I added one.
@ichard26 ichard26 force-pushed the optimize-native-class-conversion-to-int-and-float branch from 36a4d78 to c094384 Compare January 15, 2023 01:18
@ichard26
Copy link
Collaborator Author

Hmm, I just discovered the __complex__ dunder. I'll see if I can optimize it too.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

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

Thanks! Looks good. I'll keep this open for a while in case you will add support for __complex__.

mypyc/irbuild/specialize.py Show resolved Hide resolved
@github-actions

This comment has been minimized.

@ichard26 ichard26 changed the title [mypyc] Optimize int()/float() on native classes [mypyc] Optimize int()/float()/complex() on native classes Jan 17, 2023
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@JukkaL JukkaL merged commit acf26f4 into python:master Jan 18, 2023
@ichard26 ichard26 deleted the optimize-native-class-conversion-to-int-and-float branch January 18, 2023 13:49
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