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: io.IOBase subclasses don't play nice with abc.abstractmethod
Type: Stage: resolved
Components: IO Versions: Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: abstract class instantiable when subclassing built-in types
View: 5996
Assigned To: Nosy List: Jon McMahon, josh.r
Priority: normal Keywords:

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) * (Python triager) 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:11adminsetgithub: 80139
2019-02-12 17:23:38josh.rsetstatus: open -> closed

superseder: abstract class instantiable when subclassing built-in types

nosy: + josh.r
messages: + msg335335
resolution: duplicate
stage: resolved
2019-02-10 17:37:17Jon McMahoncreate