X Tutup
Skip to content

Partially implemented Protocol subclasses are not abstract #145683

@jagapiou

Description

@jagapiou

Bug report

Bug description:

There is the following example in https://typing.python.org/en/latest/reference/protocols.html#defining-subprotocols-and-subclassing-protocols:

class SomeProto(Protocol):
    attr: int  # Note, no right hand side
    # If the body is literally just "...", explicit subclasses will
    # be treated as abstract classes if they don't implement the method.
    def method(self) -> str: ...

class ExplicitSubclass(SomeProto):
    pass

ExplicitSubclass()  # error: Cannot instantiate abstract class 'ExplicitSubclass'
                    # with abstract attributes 'attr' and 'method'

However when I run this code I do not see any error (ExplicitSubclass is initialized).

To get the desired behavior, the example would need method and attr to be explicitly marked as @abc.abstractmethod (and @property). But requiring these seems undesirable (see also #127677).

CPython versions tested on:

3.14, 3.13, 3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup