Skip to content

Should we always prohibit "abstract" attributes? #4426

@ilevkivskyi

Description

@ilevkivskyi

Currently, instantiating explicit subclasses of protocols with "abstract" attributes is prohibited:

class P(Protocol):
    x: int  # Note, no r.h.s.

class C(P):
    pass
class D(P):
    def __init__(self) -> None:
        self.x = 42

C()  # E: Cannot instantiate abstract class 'C' with abstract attribute 'x'
D()  # OK

This is feature appeared with little discussion, in particular should this be specific only to protocols or also to "normal" ABCs?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions