bpo-32999: Fix ABC.__subclasscheck__ crash#6002
Conversation
| * return True | ||
| */ | ||
| _Py_IDENTIFIER(__mro__); | ||
| if (_PyObject_LookupAttrId(subclass, &PyId___mro__, &mro) < 0) { |
ilevkivskyi
left a comment
There was a problem hiding this comment.
Thanks! Just two minor comments
| self.assertIsInstance(42, A) | ||
| self.assertIsInstance(42, (A,)) | ||
|
|
||
| def test_issubclass(self): |
There was a problem hiding this comment.
I would rather make the test name more specific, or add few more corner cases here.
| */ | ||
| _Py_IDENTIFIER(__mro__); | ||
| if (_PyObject_LookupAttrId(subclass, &PyId___mro__, &mro) < 0) { | ||
| return NULL; |
There was a problem hiding this comment.
Maybe this should be goto end; or similar? (for clean-up)
|
|
||
| end: | ||
| Py_XDECREF(mro); | ||
| Py_XDECREF(impl); |
There was a problem hiding this comment.
Looks to me impl can't be NULL here.
| __mro__ = 42 # __mro__ is not tuple | ||
|
|
||
| with self.assertRaises(TypeError): | ||
| self.assertTrue(issubclass(C(), A)) |
There was a problem hiding this comment.
self.assertTrue is not needed.
| if (_add_to_weak_set(&impl->_abc_cache, subclass) < 0) { | ||
| for (pos = 0; pos < PyTuple_GET_SIZE(mro); pos++) { | ||
| PyObject *mro_item = PyTuple_GET_ITEM(mro, pos); | ||
| if (mro_item == NULL) { |
There was a problem hiding this comment.
Is this check needed? If it is a must, we need to set an exception in this branch, otherwise we will return NULL while no exception set.
| static int | ||
| compute_abstract_methods(PyObject *self) | ||
| { | ||
| _Py_IDENTIFIER(__abstractmethods__); |
There was a problem hiding this comment.
Why don't we define these identifiers at the top level?
There was a problem hiding this comment.
I prefer local variable when it's used only in one function.
If you prefer top level, I'll revert unnecessary changes.
There was a problem hiding this comment.
I usually move them to the top level as it's hard to track if a variable like this is used in one or in many functions. Really up to you though, I'm OK about this change either way.
zhangyangyu
left a comment
There was a problem hiding this comment.
LGTM. +1 about the unittest name could be more specific, but it's just a preference.
|
I'm bad at English, including vocabulary. Would you propose better name, instead of just saying "specific"? |
|
I mean something like |
|
Thanks @methane for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7. |
(cherry picked from commit fc7df0e) Co-authored-by: INADA Naoki <methane@users.noreply.github.com>
|
GH-6014 is a backport of this pull request to the 3.7 branch. |
bpo-33018 (pythonGH-5944) fixed bpo-32999 too. So fc7df0e is not required anymore. Revert it except test case.
bpo-33018 (pythonGH-5944) fixed bpo-32999 too. So fc7df0e is not required anymore. Revert it except test case. (cherry picked from commit f757b72) Co-authored-by: INADA Naoki <methane@users.noreply.github.com>
bpo-33018 (pythonGH-5944) fixed bpo-32999 too. So fc7df0e is not required anymore. Revert it except test case.
C implementation of
ABC.__subclasscheck__(cls, subclass)crashed whensubclassis not type object.This commit makes C implementation more similar to Python implementation.
https://bugs.python.org/issue32999