Skip to content

Should it be possible to subclass TextIO without implementing all abstract methods? #112

Closed
@gvanrossum

Description

@gvanrossum

Currently this fails:

from typing import TextIO
class MyTextFile(TextIO):
    pass
f = MyTextFile()  # raises TypeError

The instantiation fails with TypeError: Can't instantiate abstract class MyTextFile with abstract methods <long list of methods>.

Mark Shannon pointed this out. I have to think about whether this is important to support; a simple work-around is to use TextIO.register() instead:

from typing import TextIO
class MyTextFile:
    pass
TextIO.register(MyTextFile)
f = MyTextFile()  # OK

Metadata

Metadata

Assignees

No one assigned

    Labels

    resolution: out of scopeThe idea or discussion was out of scope for this repositorytopic: featureDiscussions about new features for Python's type annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions