Skip to content

false positive: abstract-method for typing.Protocol inheritance with abc.abstractmethod #7209

Closed
@huwcbjones

Description

@huwcbjones

Bug description

It appears that if:

  1. you have two protocols that have abstract methods
  2. create a third protocol that inherits from both of them and does not implement the abstractmethods (because a protocol is not a concrete implementation)

pylint thinks that the abstract methods from the parent classes are not implemented.
From reading PEP 544 I believe this is acceptable and therefore shouldn't be a false positive.

"""FooBar Protocol"""
# pylint: disable=too-few-public-methods,disallowed-name
from abc import abstractmethod
from typing import Protocol, Literal


class FooProtocol(Protocol):
    """Foo Protocol"""

    @abstractmethod
    def foo(self) -> Literal["foo"]:  # pylint: disable=invalid-name
        """foo method"""


class BarProtocol(Protocol):
    """Bar Protocol"""
    @abstractmethod
    def bar(self) -> Literal["bar"]:
        """bar method"""


class FooBarProtocol(FooProtocol, BarProtocol, Protocol):
    """FooBar Protocol"""


class FooBar(FooBarProtocol):
    """FooBar object"""

    def bar(self) -> Literal["bar"]:
        return "bar"

    def foo(self) -> Literal["foo"]:
        return "foo"

Configuration

No response

Command used

pylint mwe.py

Pylint output

************* Module mwe
mwe.py:22:0: W0223: Method 'bar' is abstract in class 'BarProtocol' but is not overridden (abstract-method)
mwe.py:22:0: W0223: Method 'foo' is abstract in class 'FooProtocol' but is not overridden (abstract-method)

Expected behavior

No warnings

Pylint version

pylint 2.13.9
astroid 2.11.7
Python 3.9.1 (default, Mar 15 2021, 18:22:18)
[Clang 12.0.0 (clang-1200.0.32.27)]

pylint3 2.2.2
astroid 2.1.0
Python 3.7.3 (default, Jun  2 2021, 09:53:27)
[GCC 8.3.0]

OS / Environment

macOS 11.6.1

~Debian Buster

Additional dependencies

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions