-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented a check for an attempt to invoke a static or class method…
… that is marked abstract. This addresses python/mypy#14939.
- Loading branch information
1 parent
773b619
commit c51bb4b
Showing
5 changed files
with
88 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
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
1 change: 1 addition & 0 deletions
1
packages/pyright-internal/src/localization/package.nls.en-us.json
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
55 changes: 55 additions & 0 deletions
55
packages/pyright-internal/src/tests/samples/abstractClass10.py
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,55 @@ | ||
# This sample tests the detection of static or class method invocations | ||
# where the method is marked abstract. | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
|
||
class A(ABC): | ||
@staticmethod | ||
@abstractmethod | ||
def method1() -> None: | ||
... | ||
|
||
@classmethod | ||
@abstractmethod | ||
def method2(cls) -> None: | ||
... | ||
|
||
|
||
# This should generate an error. | ||
A.method1() | ||
|
||
# This should generate an error. | ||
A.method2() | ||
|
||
|
||
class B(A): | ||
@staticmethod | ||
def method1() -> None: | ||
# This should generate an error. | ||
return super().method1() | ||
|
||
@classmethod | ||
def method2(cls) -> None: | ||
# This should generate an error. | ||
return super().method2() | ||
|
||
|
||
B.method1() | ||
B.method2() | ||
|
||
|
||
def func1(a: type[A]): | ||
a.method1() | ||
a.method2() | ||
|
||
|
||
class C(A): | ||
... | ||
|
||
|
||
# This should generate an error. | ||
C.method1() | ||
|
||
# This should generate an error. | ||
C.method2() |