Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue29822

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:inspect.isabstract does not work on abstract base classes during __init_subclass__
Type:behaviorStage:resolved
Components:Library (Lib)Versions:Python 3.7, Python 3.6
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To:Nosy List: So8res, levkivskyi, ncoghlan, serhiy.storchaka, yselivanov
Priority:normalKeywords:

Created on2017-03-15 17:06 bySo8res, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 678mergedSo8res,2017-03-15 18:50
PR 1979mergedSo8res,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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)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)*(Python committer)Date: 2017-06-07 04:22
Thank you for your contribution Nate.
History
DateUserActionArgs
2022-04-11 14:58:44adminsetgithub: 74008
2017-06-07 04:22:59serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: +msg295314

stage: backport needed -> resolved
2017-06-07 04:21:36serhiy.storchakasetmessages: +msg295313
2017-06-07 00:19:20So8ressetpull_requests: +pull_request2045
2017-04-24 17:09:07serhiy.storchakasetstage: patch review -> backport needed
versions: - Python 3.5
2017-04-24 17:06:19serhiy.storchakasetmessages: +msg292231
2017-03-18 17:52:51serhiy.storchakasetmessages: +msg289823
2017-03-18 13:57:08serhiy.storchakasetnosy: +ncoghlan
2017-03-18 07:04:13So8ressetmessages: +msg289794
2017-03-18 05:46:49serhiy.storchakasettype: behavior
components: + Library (Lib)
versions: + Python 3.5, Python 3.6
nosy: +yselivanov

messages: +msg289793
stage: patch review
2017-03-18 01:09:13levkivskyisetnosy: +serhiy.storchaka,levkivskyi
messages: +msg289788
2017-03-15 18:50:05So8ressetpull_requests: +pull_request556
2017-03-15 17:06:09So8rescreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp