black/tests/data/cases/preview_dummy_implementations.py
Shantanu 4ceed0b958
Remove is_function_or_class helper footgun (#4133)
This is a no-op change.

That function was not a good way to tell if something is a function or a
class, since it basically only worked for async functions by accident
(the parent of a suite / simple_stmt of async function body is a
funcdef).
2024-01-01 17:36:49 -08:00

146 lines
2.2 KiB
Python

# flags: --preview
from typing import NoReturn, Protocol, Union, overload
class Empty:
...
def dummy(a): ...
async def other(b): ...
@overload
def a(arg: int) -> int: ...
@overload
def a(arg: str) -> str: ...
@overload
def a(arg: object) -> NoReturn: ...
def a(arg: Union[int, str, object]) -> Union[int, str]:
if not isinstance(arg, (int, str)):
raise TypeError
return arg
class Proto(Protocol):
def foo(self, a: int) -> int:
...
def bar(self, b: str) -> str: ...
def baz(self, c: bytes) -> str:
...
def dummy_two():
...
@dummy
def dummy_three():
...
def dummy_four():
...
@overload
def b(arg: int) -> int: ...
@overload
def b(arg: str) -> str: ...
@overload
def b(arg: object) -> NoReturn: ...
def b(arg: Union[int, str, object]) -> Union[int, str]:
if not isinstance(arg, (int, str)):
raise TypeError
return arg
def has_comment():
... # still a dummy
if some_condition:
...
if already_dummy: ...
class AsyncCls:
async def async_method(self):
...
async def async_function(self):
...
@decorated
async def async_function(self):
...
# output
from typing import NoReturn, Protocol, Union, overload
class Empty: ...
def dummy(a): ...
async def other(b): ...
@overload
def a(arg: int) -> int: ...
@overload
def a(arg: str) -> str: ...
@overload
def a(arg: object) -> NoReturn: ...
def a(arg: Union[int, str, object]) -> Union[int, str]:
if not isinstance(arg, (int, str)):
raise TypeError
return arg
class Proto(Protocol):
def foo(self, a: int) -> int: ...
def bar(self, b: str) -> str: ...
def baz(self, c: bytes) -> str: ...
def dummy_two(): ...
@dummy
def dummy_three(): ...
def dummy_four(): ...
@overload
def b(arg: int) -> int: ...
@overload
def b(arg: str) -> str: ...
@overload
def b(arg: object) -> NoReturn: ...
def b(arg: Union[int, str, object]) -> Union[int, str]:
if not isinstance(arg, (int, str)):
raise TypeError
return arg
def has_comment(): ... # still a dummy
if some_condition:
...
if already_dummy:
...
class AsyncCls:
async def async_method(self): ...
async def async_function(self): ...
@decorated
async def async_function(self): ...