-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make protocols be defined as abstract
- Loading branch information
1 parent
ed404d3
commit 27e56c4
Showing
3 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Fixes false positive ``abstract-method`` on Protocol classes. | ||
|
||
Closes #7209 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""Test that classes inheriting from protocols should not warn about abstract-method.""" | ||
# pylint: disable=too-few-public-methods,disallowed-name,invalid-name | ||
from abc import abstractmethod | ||
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 FooBar(FooBarProtocol): | ||
"""FooBar object""" | ||
|
||
def bar(self) -> Literal["bar"]: | ||
return "bar" | ||
|
||
def foo(self) -> Literal["foo"]: | ||
return "foo" |