Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io.IOBase subclasses don't play nice with abc.abstractmethod #80139

Closed
JonMcMahon mannequin opened this issue Feb 10, 2019 · 2 comments
Closed

io.IOBase subclasses don't play nice with abc.abstractmethod #80139

JonMcMahon mannequin opened this issue Feb 10, 2019 · 2 comments
Labels

Comments

@JonMcMahon
Copy link
Mannequin

JonMcMahon mannequin commented Feb 10, 2019

BPO 35958
Nosy @MojoVampire
Superseder
  • bpo-5996: abstract class instantiable when subclassing built-in types
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-02-12.17:23:38.104>
    created_at = <Date 2019-02-10.17:37:17.613>
    labels = ['expert-IO']
    title = "io.IOBase subclasses don't play nice with abc.abstractmethod"
    updated_at = <Date 2019-02-12.17:23:38.101>
    user = 'https://bugs.python.org/JonMcMahon'

    bugs.python.org fields:

    activity = <Date 2019-02-12.17:23:38.101>
    actor = 'josh.r'
    assignee = 'none'
    closed = True
    closed_date = <Date 2019-02-12.17:23:38.104>
    closer = 'josh.r'
    components = ['IO']
    creation = <Date 2019-02-10.17:37:17.613>
    creator = 'Jon McMahon'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 35958
    keywords = []
    message_count = 2.0
    messages = ['335166', '335335']
    nosy_count = 2.0
    nosy_names = ['josh.r', 'Jon McMahon']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '5996'
    type = None
    url = 'https://bugs.python.org/issue35958'
    versions = ['Python 3.6']

    @JonMcMahon
    Copy link
    Mannequin Author

    JonMcMahon mannequin commented Feb 10, 2019

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

    @JonMcMahon JonMcMahon mannequin added the topic-IO label Feb 10, 2019
    @MojoVampire
    Copy link
    Mannequin

    MojoVampire mannequin commented Feb 12, 2019

    This looks to be a general problem with built-in classes using ABCMeta, per bpo-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 bpo-5996 (abstract class instantiable when subclassing dict).

    @MojoVampire MojoVampire mannequin closed this as completed Feb 12, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants