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

gh-91603: Speed up isinstance/issubclass on union types #91631

Merged
merged 7 commits into from
Apr 28, 2022

Conversation

uriyyo
Copy link
Member

@uriyyo uriyyo commented Apr 17, 2022

@uriyyo
Copy link
Member Author

uriyyo commented Apr 17, 2022

@JelleZijlstra I have unified logic for tuple and types.UnionType checks. Now they work in the same way.

@@ -348,12 +294,6 @@ static PyMemberDef union_members[] = {
{0}
};

static PyMethodDef union_methods[] = {
{"__instancecheck__", union_instancecheck, METH_O},
Copy link
Member

Choose a reason for hiding this comment

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

I think we may still want to keep those methods too in case people call them directly. Let me think about it some more.

Copy link
Member

Choose a reason for hiding this comment

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

On second thought, I don't think we need to keep these. The language reference (https://docs.python.org/3/library/stdtypes.html#types-union) explicitly says that isinstance() works with union objects, so we don't need __instancecheck__ to be present to indicate that they work with isinstance().

So no change needed here.

…e-91603.hYw1Lv.rst

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com>
Objects/unionobject.c Show resolved Hide resolved
@@ -348,12 +294,6 @@ static PyMemberDef union_members[] = {
{0}
};

static PyMethodDef union_methods[] = {
{"__instancecheck__", union_instancecheck, METH_O},
Copy link
Member

Choose a reason for hiding this comment

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

On second thought, I don't think we need to keep these. The language reference (https://docs.python.org/3/library/stdtypes.html#types-union) explicitly says that isinstance() works with union objects, so we don't need __instancecheck__ to be present to indicate that they work with isinstance().

So no change needed here.

Objects/unionobject.c Show resolved Hide resolved
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Objects/abstract.c Outdated Show resolved Hide resolved
Objects/abstract.c Outdated Show resolved Hide resolved
Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Looks good to me, but since it's a C change I'm going to run it through the buildbots. Hopefully @Fidget-Spinner can take a look too.

@JelleZijlstra JelleZijlstra added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 25, 2022
@bedevere-bot
Copy link

🤖 New build scheduled with the buildbot fleet by @JelleZijlstra for commit 20c44f8 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 25, 2022
@AlexWaygood AlexWaygood added performance Performance or resource usage topic-typing labels Apr 25, 2022
@uriyyo
Copy link
Member Author

uriyyo commented Apr 28, 2022

@Fidget-Spinner It will be great if you can review this PR.

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a comment

Choose a reason for hiding this comment

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

I'm glad that we managed to shrink unionobject's code.

Lib/test/test_types.py Show resolved Hide resolved
@Fidget-Spinner
Copy link
Member

The test_gdb test on s390x Fedora Clang PR worker is awfully confusing. However, browsing past commit history I can see it failing occasionally, so I don't think it's related.

@Fidget-Spinner Fidget-Spinner merged commit 0ef8d92 into python:main Apr 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage topic-typing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants