summaryrefslogtreecommitdiff
path: root/tests/functional/p/protocol_classes_abstract.py
blob: ad8ec5cf5cef3fa3c645eb8ed27c23fb9799f1f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""Test that classes inheriting directly from Protocol should not warn about abstract-method."""

# pylint: disable=too-few-public-methods,disallowed-name,invalid-name

from abc import abstractmethod, ABCMeta
from typing import Protocol, Literal


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

    @abstractmethod
    def foo(self) -> Literal["foo"]:
        """foo method"""

    def foo_no_abstract(self) -> Literal["foo"]:
        """foo not abstract method"""


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


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

class BarParent(BarProtocol): # [abstract-method]
    """Doesn't subclass typing.Protocol directly"""

class IndirectProtocol(FooProtocol):  # [abstract-method]
    """Doesn't subclass typing.Protocol directly"""

class AbcProtocol(FooProtocol, metaclass=ABCMeta):
    """Doesn't subclass typing.Protocol but uses metaclass directly"""

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

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

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