This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ABCs don't fail metaclass instantiation
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.4, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: abstract class instantiable when subclassing built-in types
View: 5996
Assigned To: Nosy List: Devin Jeanpierre, cheryl.sabella, luiz.poleto
Priority: normal Keywords:

Created on 2015-05-18 21:48 by Devin Jeanpierre, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (3)
msg243540 - (view) Author: Devin Jeanpierre (Devin Jeanpierre) * Date: 2015-05-18 21:48
If a subclass has abstract methods, it fails to instantiate... unless it's a metaclass, and then it succeeds.

>>> import abc
>>> class A(metaclass=abc.ABCMeta):
...     @abc.abstractmethod
...     def foo(self): pass
... 
>>> class B(A): pass
... 
>>> B()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class B with abstract methods foo
>>> class C(A, type): pass
... 
>>> class c(metaclass=C): pass
... 
>>> C('', (), {})
<class '__main__.'>
>>>
msg266295 - (view) Author: Luiz Poleto (luiz.poleto) * Date: 2016-05-25 03:49
This seems to be related to issues #5996 and #26306.
msg336578 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-02-25 23:32
Closing as a duplicate as Luiz suggested.
History
Date User Action Args
2022-04-11 14:58:17adminsetgithub: 68423
2019-02-25 23:32:20cheryl.sabellasetstatus: open -> closed

superseder: abstract class instantiable when subclassing built-in types

nosy: + cheryl.sabella
messages: + msg336578
resolution: duplicate
stage: resolved
2016-05-25 03:49:34luiz.poletosetnosy: + luiz.poleto
messages: + msg266295
2015-05-18 21:48:56Devin Jeanpierrecreate