GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-34441: Fix ABC.__subclasscheck__ crash on a class with invalid __subclasses__ by izbyshev · Pull Request #8835 · python/cpython

Conversation

@izbyshev

@izbyshev izbyshev commented Aug 20, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The missing NULL check was reported by Svace static analyzer.

https://bugs.python.org/issue34441

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Alexey Izbyshev
bpo-34441: Fix ABC.__subclasscheck__ crash on a class with non-callab…
377d01b
…le __subclasses__

The missing NULL check was reported by Svace static analyzer.
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Aug 20, 2018
@bedevere-bot bedevere-bot added the awaiting review label Aug 20, 2018
@ilevkivskyi ilevkivskyi added the needs backport to 3.7 label Aug 20, 2018
ilevkivskyi
ilevkivskyi approved these changes Aug 20, 2018
View reviewed changes

@ilevkivskyi ilevkivskyi left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks! LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting review labels Aug 20, 2018
serhiy-storchaka
serhiy-storchaka reviewed Aug 20, 2018
View reviewed changes
Comment thread Lib/test/test_abc.py Outdated
with self.assertRaises(TypeError):
issubclass(C(), A)

# bpo-34441: Check that issubclass() doesn't crash on bogus classes

@serhiy-storchaka serhiy-storchaka Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Would be nice to add also tests for following cases:

  • __subclasses__ is a callable with wrong signature.
  • __subclasses__ raises an exception explicitly.
  • __subclasses__ returns not a list.
  • __subclasses__ returns a list containing not a type.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@izbyshev izbyshev Aug 20, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks, I've added those cases.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Alexey Izbyshev
Add tests for various unusual __subclasses__
fa3bdae
berkerpeksag
berkerpeksag reviewed Aug 20, 2018
View reviewed changes
Comment thread Lib/test/test_abc.py Outdated
lambda: [42],
]

for bs in bogus_subclasses:

@berkerpeksag berkerpeksag Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nit: bs -> cls

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@berkerpeksag berkerpeksag Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

And it would be nice to use a subTest() here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@izbyshev izbyshev Aug 20, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nit: bs -> cls

Why? bs denotes (would-be) callables, not classes.

And it would be nice to use a subTest() here.

Thank you, fixed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@serhiy-storchaka serhiy-storchaka Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Then may be use func?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@izbyshev izbyshev Aug 20, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

OK!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_abc.py Outdated
issubclass(int, S)

# Also check that issubclass() propagates exceptions raised by
# __subclasses__

@berkerpeksag berkerpeksag Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Nit: Please end all sentences with a full stop.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@izbyshev izbyshev Aug 20, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Misc/NEWS.d/next/Library/2018-08-20-16-48-32.bpo-34441._zx9lU.rst Outdated
@@ -0,0 +1,2 @@
Fix crash when an ``ABC``-derived class with non-callable ``__subclasses__`` is passed as the
second argument to ``issubclass()``.

@berkerpeksag berkerpeksag Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

``issubclass()`` -> :func:`issubclass`

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@berkerpeksag berkerpeksag Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Please add "Patch by Your Name." and wrap lines at 80 chars.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@izbyshev izbyshev Aug 20, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Fixed, thank you.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Alexey Izbyshev
Fix NEWS entry and reformat it with blurb
a3cd050
serhiy-storchaka
serhiy-storchaka reviewed Aug 20, 2018
View reviewed changes
Comment thread Lib/test/test_abc.py Outdated
# bpo-34441: Check that issubclass() doesn't crash on bogus classes
bogus_subclasses = [
None,
lambda x: None,

@serhiy-storchaka serhiy-storchaka Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Make it returning a valid result: [].

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@izbyshev izbyshev Aug 20, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Alexey Izbyshev added 3 commits August 20, 2018 20:22
Alexey Izbyshev
End sentences with a full stop
432f6df
Alexey Izbyshev
Test an invalid __subclasses__ signature with a valid return type
56b21e8
Alexey Izbyshev
Use subTest() to distinguish iterations
7df825e
serhiy-storchaka
serhiy-storchaka reviewed Aug 20, 2018
View reviewed changes
Comment thread Misc/NEWS.d/next/Library/2018-08-20-16-48-32.bpo-34441._zx9lU.rst Outdated
@@ -1,2 +1,3 @@
Fix crash when an ``ABC``-derived class with non-callable ``__subclasses__`` is passed as the
second argument to ``issubclass()``.
Fix crash when an ``ABC``-derived class with non-callable ``__subclasses__``

@serhiy-storchaka serhiy-storchaka Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Non-callable __subclasses__ is not the only cause of a crash.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@izbyshev izbyshev Aug 20, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You're right. I've also updated the PR name.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Alexey Izbyshev added 2 commits August 20, 2018 20:35
Alexey Izbyshev
Generalize NEWS entry
dcf2e04
Alexey Izbyshev
bs -> func
7d3c5ec
@izbyshev izbyshev changed the title bpo-34441: Fix ABC.__subclasscheck__ crash on a class with non-callab… bpo-34441: Fix ABC.__subclasscheck__ crash on a class with invalid __subclasses__ Aug 20, 2018
berkerpeksag
berkerpeksag reviewed Aug 20, 2018
View reviewed changes
Comment thread Lib/test/test_abc.py Outdated
__subclasses__ = func

with self.subTest(i=i), \
self.assertRaises(TypeError):

@berkerpeksag berkerpeksag Aug 20, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This is mostly a cosmetic change, I find the following style more readable (and we usually try to avoid using a backslash if it's possible to write a readable code):

with self.subTest(i=i):
    self.assertRaises(TypeError, issubclass, int, S)

Or:

with self.subTest(i=i):
    with self.assertRaises(TypeError):
        issubclass(int, S)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@izbyshev izbyshev Aug 20, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

OK, I went for the second one for consistency with other checks.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Alexey Izbyshev
Use nested with statements for readability
72cb031
berkerpeksag
berkerpeksag approved these changes Aug 20, 2018
View reviewed changes

@berkerpeksag berkerpeksag left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, thank you! :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
serhiy-storchaka
serhiy-storchaka approved these changes Aug 20, 2018
View reviewed changes
@berkerpeksag
berkerpeksag merged commit cdbf50c into python:master Aug 20, 2018
@miss-islington

miss-islington commented Aug 20, 2018

Copy link
Copy Markdown
Contributor

Thanks @izbyshev for the PR, and @berkerpeksag for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the awaiting merge label Aug 20, 2018
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 20, 2018
Alexey Izbyshev @miss-islington
bpo-34441: Fix ABC.__subclasscheck__ crash on classes with invalid __…
bd41aeb
…subclasses__ (pythonGH-8835)

The missing NULL check was reported by Svace static analyzer.
(cherry picked from commit cdbf50c)

Co-authored-by: Alexey Izbyshev <[email protected]>
@bedevere-bot

bedevere-bot commented Aug 20, 2018

Copy link
Copy Markdown

GH-8840 is a backport of this pull request to the 3.7 branch.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the needs backport to 3.7 label Aug 20, 2018
@izbyshev
izbyshev deleted the bpo-34441 branch August 20, 2018 20:30
miss-islington added a commit that referenced this pull request Aug 20, 2018
@miss-islington Alexey Izbyshev
bpo-34441: Fix ABC.__subclasscheck__ crash on classes with invalid __…
d1f0ccc
…subclasses__ (GH-8835)

The missing NULL check was reported by Svace static analyzer.
(cherry picked from commit cdbf50c)

Co-authored-by: Alexey Izbyshev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@berkerpeksag berkerpeksag berkerpeksag approved these changes
@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@ilevkivskyi ilevkivskyi ilevkivskyi approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@izbyshev @miss-islington @bedevere-bot @berkerpeksag @serhiy-storchaka @ilevkivskyi @the-knights-who-say-ni
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.