Issue 24235: ABCs don't fail metaclass instantiation
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) * ![]() |
Date: 2019-02-25 23:32 | |
Closing as a duplicate as Luiz suggested. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:17 | admin | set | github: 68423 |
| 2019-02-25 23:32:20 | cheryl.sabella | set | status: open -> closed superseder: abstract class instantiable when subclassing built-in types nosy:
+ cheryl.sabella |
| 2016-05-25 03:49:34 | luiz.poleto | set | nosy:
+ luiz.poleto messages: + msg266295 |
| 2015-05-18 21:48:56 | Devin Jeanpierre | create | |
