|
| 1 | +# See https://peps.python.org/pep-0484/#positional-only-arguments |
| 2 | +# for the full details on which arguments using the older syntax should/shouldn't |
| 3 | +# be considered positional-only arguments by type checkers. |
| 4 | +from typing import Self |
| 5 | + |
| 6 | +def bad(__x: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 7 | +def also_bad(__x: int, __y: str) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 8 | +def still_bad(__x_: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 9 | + |
| 10 | +def no_args() -> None: ... |
| 11 | +def okay(__x__: int) -> None: ... |
| 12 | +# The first argument isn't positional-only, so logically the second can't be either: |
| 13 | +def also_okay(x: int, __y: str) -> None: ... |
| 14 | +def fine(x: bytes, /) -> None: ... |
| 15 | +def no_idea_why_youd_do_this(__x: int, /, __y: str) -> None: ... |
| 16 | +def cool(_x__: int) -> None: ... |
| 17 | +def also_cool(x__: int) -> None: ... |
| 18 | +def unclear_from_pep_484_if_this_is_positional_or_not(__: str) -> None: ... |
| 19 | +def _(_: int) -> None: ... |
| 20 | + |
| 21 | +class Foo: |
| 22 | + def bad(__self) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 23 | + @staticmethod |
| 24 | + def bad2(__self) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 25 | + def bad3(__self, __x: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 26 | + def still_bad(self, __x_: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 27 | + @staticmethod |
| 28 | + def this_is_bad_too(__x: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 29 | + @classmethod |
| 30 | + def not_good(cls, __foo: int) -> None: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 31 | + |
| 32 | + # The first non-self argument isn't positional-only, so logically the second can't be either: |
| 33 | + def okay1(self, x: int, __y: int) -> None: ... |
| 34 | + # Same here: |
| 35 | + @staticmethod |
| 36 | + def okay2(x: int, __y_: int) -> None: ... |
| 37 | + @staticmethod |
| 38 | + def no_args() -> int: ... |
| 39 | + def okay3(__self__, __x__: int, __y: str) -> None: ... |
| 40 | + def okay4(self, /) -> None: ... |
| 41 | + def okay5(self, x: int, /) -> None: ... |
| 42 | + def okay6(__self, /) -> None: ... |
| 43 | + def cool(_self__: int) -> None: ... |
| 44 | + def also_cool(self__: int) -> None: ... |
| 45 | + def unclear_from_pep_484_if_this_is_positional_or_not(__: str) -> None: ... |
| 46 | + def _(_: int) -> None: ... |
| 47 | + @classmethod |
| 48 | + def fine(cls, foo: int, /) -> None: ... |
| 49 | + |
| 50 | +class Metaclass(type): |
| 51 | + @classmethod |
| 52 | + def __new__(mcls, __name: str, __bases: tuple[type, ...], __namespace: dict, **kwds) -> Self: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 53 | + |
| 54 | +class Metaclass2(type): |
| 55 | + @classmethod |
| 56 | + def __new__(metacls, __name: str, __bases: tuple[type, ...], __namespace: dict, **kwds) -> Self: ... # Y063 Use PEP-570 syntax to indicate positional-only arguments |
| 57 | + |
| 58 | +class GoodMetaclass(type): |
| 59 | + @classmethod |
| 60 | + def __new__(mcls, name: str, bases: tuple[type, ...], namespace: dict, /, **kwds) -> Self: ... |
| 61 | + |
| 62 | +class GoodMetaclass2(type): |
| 63 | + @classmethod |
| 64 | + def __new__(metacls, name: str, bases: tuple[type, ...], namespace: dict, /, **kwds) -> Self: ... |
0 commit comments