GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| with self.assertRaises(TypeError): | ||
| issubclass(C(), A) | ||
|
|
||
| # bpo-34441: Check that issubclass() doesn't crash on bogus classes |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| lambda: [42], | ||
| ] | ||
|
|
||
| for bs in bogus_subclasses: |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nit: bs -> cls
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
OK!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| issubclass(int, S) | ||
|
|
||
| # Also check that issubclass() propagates exceptions raised by | ||
| # __subclasses__ |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -0,0 +1,2 @@ | |||
| Fix crash when an ``ABC``-derived class with non-callable ``__subclasses__`` is passed as the | |||
| second argument to ``issubclass()``. | |||
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
``issubclass()`` -> :func:`issubclass`
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thank you.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| # bpo-34441: Check that issubclass() doesn't crash on bogus classes | ||
| bogus_subclasses = [ | ||
| None, | ||
| lambda x: None, |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| @@ -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__`` | |||
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
| __subclasses__ = func | ||
|
|
||
| with self.subTest(i=i), \ | ||
| self.assertRaises(TypeError): |
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem 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.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you! :)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @izbyshev for the PR, and @berkerpeksag for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…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]>
|
GH-8840 is a backport of this pull request to the 3.7 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…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]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.