Issue35958
Created on 2019-02-10 17:37 by Jon McMahon, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (2) | |||
|---|---|---|---|
| msg335166 - (view) | Author: Jon McMahon (Jon McMahon) | Date: 2019-02-10 17:37 | |
Subclasses of io.IOBase can be instantiated with abstractmethod()s, even though ABCs are supposed to prevent this from happening. I'm guessing this has to do with io using the _io C module because the alternative pure-python implementation _pyio doesn't seem to have this issue. I'm using Python 3.6.7
>>> import _pyio
>>> import io
>>> import abc
>>> class TestPurePython(_pyio.IOBase):
... @abc.abstractmethod
... def foo(self):
... print('Pure python implementation')
...
>>> class TestCExtension(io.IOBase):
... @abc.abstractmethod
... def bar(self):
... print('C extension implementation')
...
>>> x=TestPurePython()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Can't instantiate abstract class TestPurePython with abstract methods foo
>>> y=TestCExtension()
>>> y.bar()
C extension implementation
>>>
|
|||
| msg335335 - (view) | Author: Josh Rosenberg (josh.r) * ![]() |
Date: 2019-02-12 17:23 | |
This looks to be a general problem with built-in classes using ABCMeta, per #31127 (Abstract classes derived from built-in classes don't block instance creation). Progress (or lack thereof) is being tracked on the more specifically named #5996 (abstract class instantiable when subclassing dict). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:11 | admin | set | github: 80139 |
| 2019-02-12 17:23:38 | josh.r | set | status: open -> closed superseder: abstract class instantiable when subclassing built-in types nosy:
+ josh.r |
| 2019-02-10 17:37:17 | Jon McMahon | create | |
