
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2017-03-15 17:06 bySo8res, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 678 | merged | So8res,2017-03-15 18:50 | |
| PR 1979 | merged | So8res,2017-06-07 00:19 | |
| Messages (8) | |||
|---|---|---|---|
| msg289682 -(view) | Author: Nate Soares (So8res)* | Date: 2017-03-15 17:06 | |
Here's an example test that fails:def test_isabstract_during_init_subclass(self): from abc import ABCMeta, abstractmethod isabstract_checks = [] class AbstractChecker(metaclass=ABCMeta): def __init_subclass__(cls): abstract_checks.append(inspect.isabstract(cls)) class AbstractClassExample(AbstractChecker): @abstractmethod def foo(self): pass class ClassExample(AbstractClassExample): def foo(self): pass self.assertEqual(isabstract_checks, [True, False])To run the test, you'll need to be on a version of python wherebpo-29581 is fixed (e.g., a cpython branch withhttps://github.com/python/cpython/pull/527 merged) in order for __init_subclass__ to work with ABCMeta at all in the first place. I have a simple patch to inspect.isabstract that fixes this, and will make a PR shortly. | |||
| msg289788 -(view) | Author: Ivan Levkivskyi (levkivskyi)*![]() | Date: 2017-03-18 01:09 | |
Serhiy, sorry for a distraction, but it looks like here is one more situation where inspect.isabstract is problematic, similar to what was discussed inhttp://bugs.python.org/issue29638 recently. | |||
| msg289793 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-03-18 05:46 | |
Is this an alternate fix ofissue29638? | |||
| msg289794 -(view) | Author: Nate Soares (So8res)* | Date: 2017-03-18 07:04 | |
I didn't know aboutissue29638, and I'm not sure whether my PR fixes it. Looking at that bug, I don't think that my PR would fix it, because I still trust TPFLAGS_IS_ABSTRACT when __abstractmethods__ exists. That said, I'm not clear on how the cache works, so it's possible that my PR would fix 29638.My issue appears when one uses py3.6's new __init_subclass__ hook with an ABC. __init_subclass__ is run by type.__new__, which means that, as of py3.6, users can (in a natural/reasonable way) inspect ABCMeta classes before ABCMeta.__new__ finishes executing. I didn't see any reasonable way to have ABCMeta.__new__ finish setting up the ABC before calling super().__new__, so I figured the fix should go into inspect.isabstract. But there may be better solutions I just didn't think of. | |||
| msg289823 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-03-18 17:52 | |
LGTM, but would be nice if Yury and Nick take a look. | |||
| msg292231 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-04-24 17:06 | |
New changesetfcfe80ec2592fed8b3941c79056a8737abef7d3b by Serhiy Storchaka (Nate) in branch 'master':bpo-29822: Make inspect.isabstract() work during __init_subclass__. (#678)https://github.com/python/cpython/commit/fcfe80ec2592fed8b3941c79056a8737abef7d3b | |||
| msg295313 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-06-07 04:21 | |
New changeset09b6c0c71ea944f7e8b46998f3ebaf5b9fbe15f6 by Serhiy Storchaka (Nate) in branch '3.6':[3.6]bpo-29822: make inspect.isabstract() work during __init_subclass__ (#1979)https://github.com/python/cpython/commit/09b6c0c71ea944f7e8b46998f3ebaf5b9fbe15f6 | |||
| msg295314 -(view) | Author: Serhiy Storchaka (serhiy.storchaka)*![]() | Date: 2017-06-07 04:22 | |
Thank you for your contribution Nate. | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:44 | admin | set | github: 74008 |
| 2017-06-07 04:22:59 | serhiy.storchaka | set | status: open -> closed resolution: fixed messages: +msg295314 stage: backport needed -> resolved |
| 2017-06-07 04:21:36 | serhiy.storchaka | set | messages: +msg295313 |
| 2017-06-07 00:19:20 | So8res | set | pull_requests: +pull_request2045 |
| 2017-04-24 17:09:07 | serhiy.storchaka | set | stage: patch review -> backport needed versions: - Python 3.5 |
| 2017-04-24 17:06:19 | serhiy.storchaka | set | messages: +msg292231 |
| 2017-03-18 17:52:51 | serhiy.storchaka | set | messages: +msg289823 |
| 2017-03-18 13:57:08 | serhiy.storchaka | set | nosy: +ncoghlan |
| 2017-03-18 07:04:13 | So8res | set | messages: +msg289794 |
| 2017-03-18 05:46:49 | serhiy.storchaka | set | type: behavior components: + Library (Lib) versions: + Python 3.5, Python 3.6 nosy: +yselivanov messages: +msg289793 stage: patch review |
| 2017-03-18 01:09:13 | levkivskyi | set | nosy: +serhiy.storchaka,levkivskyi messages: +msg289788 |
| 2017-03-15 18:50:05 | So8res | set | pull_requests: +pull_request556 |
| 2017-03-15 17:06:09 | So8res | create | |