-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enforce PEP-570 syntax in stubs (#461)
- Loading branch information
1 parent
832be02
commit a044940
Showing
5 changed files
with
110 additions
and
3 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
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,64 @@ | ||
# See https://peps.python.org/pep-0484/#positional-only-arguments | ||
# for the full details on which arguments using the older syntax should/shouldn't | ||
# be considered positional-only arguments by type checkers. | ||
from typing import Self | ||
|
||
def bad(__x: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
def also_bad(__x: int, __y: str) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
def still_bad(__x_: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
|
||
def no_args() -> None: ... | ||
def okay(__x__: int) -> None: ... | ||
# The first argument isn't positional-only, so logically the second can't be either: | ||
def also_okay(x: int, __y: str) -> None: ... | ||
def fine(x: bytes, /) -> None: ... | ||
def no_idea_why_youd_do_this(__x: int, /, __y: str) -> None: ... | ||
def cool(_x__: int) -> None: ... | ||
def also_cool(x__: int) -> None: ... | ||
def unclear_from_pep_484_if_this_is_positional_or_not(__: str) -> None: ... | ||
def _(_: int) -> None: ... | ||
|
||
class Foo: | ||
def bad(__self) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
@staticmethod | ||
def bad2(__self) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
def bad3(__self, __x: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
def still_bad(self, __x_: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
@staticmethod | ||
def this_is_bad_too(__x: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
@classmethod | ||
def not_good(cls, __foo: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
|
||
# The first non-self argument isn't positional-only, so logically the second can't be either: | ||
def okay1(self, x: int, __y: int) -> None: ... | ||
# Same here: | ||
@staticmethod | ||
def okay2(x: int, __y_: int) -> None: ... | ||
@staticmethod | ||
def no_args() -> int: ... | ||
def okay3(__self__, __x__: int, __y: str) -> None: ... | ||
def okay4(self, /) -> None: ... | ||
def okay5(self, x: int, /) -> None: ... | ||
def okay6(__self, /) -> None: ... | ||
def cool(_self__: int) -> None: ... | ||
def also_cool(self__: int) -> None: ... | ||
def unclear_from_pep_484_if_this_is_positional_or_not(__: str) -> None: ... | ||
def _(_: int) -> None: ... | ||
@classmethod | ||
def fine(cls, foo: int, /) -> None: ... | ||
|
||
class Metaclass(type): | ||
@classmethod | ||
def __new__(mcls, __name: str, __bases: tuple[type, ...], __namespace: dict, **kwds) -> Self: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
|
||
class Metaclass2(type): | ||
@classmethod | ||
def __new__(metacls, __name: str, __bases: tuple[type, ...], __namespace: dict, **kwds) -> Self: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments | ||
|
||
class GoodMetaclass(type): | ||
@classmethod | ||
def __new__(mcls, name: str, bases: tuple[type, ...], namespace: dict, /, **kwds) -> Self: ... | ||
|
||
class GoodMetaclass2(type): | ||
@classmethod | ||
def __new__(metacls, name: str, bases: tuple[type, ...], namespace: dict, /, **kwds) -> Self: ... |