-
-
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.
Browse files
Browse the repository at this point in the history
) (cherry picked from commit 85e7d93) Co-authored-by: Dani Alcala <[email protected]>
- Loading branch information
1 parent
438025d
commit 6178e41
Showing
6 changed files
with
71 additions
and
15 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
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,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" |
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,2 @@ | ||
[testoptions] | ||
min_pyver=3.8 |
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,2 @@ | ||
abstract-method:30:0:30:15:BarParent:Method 'bar' is abstract in class 'BarProtocol' but is not overridden:UNDEFINED | ||
abstract-method:33:0:33:22:IndirectProtocol:Method 'foo' is abstract in class 'FooProtocol' but is not overridden:UNDEFINED |