[New-bugs-announce] [issue35958] io.IOBase subclasses don't play nice with abc.abstractmethod

Jon McMahon report at bugs.python.org
Sun Feb 10 12:37:17 EST 2019


New submission from Jon McMahon <jonmcmahon21 at gmail.com>:

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
>>>

----------
components: IO
messages: 335166
nosy: Jon McMahon
priority: normal
severity: normal
status: open
title: io.IOBase subclasses don't play nice with abc.abstractmethod
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue35958>
_______________________________________


More information about the New-bugs-announce mailing list