From: Scirlat Danut Date: Sun, 4 Feb 2024 16:50:59 +0000 (+0200) Subject: Added type annotations to test__utils.py (#2470) X-Git-Tag: 0.36.3~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5acee6237773f5595898126cb25cd9d4b267c5b1;p=thirdparty%2Fstarlette.git Added type annotations to test__utils.py (#2470) * added type annotations to test__utils.py * ignore functools.partial sync type * ruff fix * typo * type ignore --------- Co-authored-by: Scirlat Danut --- diff --git a/tests/test__utils.py b/tests/test__utils.py index fac57a2e..06fece58 100644 --- a/tests/test__utils.py +++ b/tests/test__utils.py @@ -1,77 +1,89 @@ import functools +from typing import Any from starlette._utils import is_async_callable -def test_async_func(): - async def async_func(): +def test_async_func() -> None: + async def async_func() -> None: ... # pragma: no cover - def func(): + def func() -> None: ... # pragma: no cover assert is_async_callable(async_func) assert not is_async_callable(func) -def test_async_partial(): - async def async_func(a, b): +def test_async_partial() -> None: + async def async_func(a: Any, b: Any) -> None: ... # pragma: no cover - def func(a, b): + def func(a: Any, b: Any) -> None: ... # pragma: no cover partial = functools.partial(async_func, 1) assert is_async_callable(partial) - partial = functools.partial(func, 1) + partial = functools.partial(func, 1) # type: ignore assert not is_async_callable(partial) -def test_async_method(): +def test_async_method() -> None: class Async: - async def method(self): + async def method(self) -> None: ... # pragma: no cover class Sync: - def method(self): + def method(self) -> None: ... # pragma: no cover assert is_async_callable(Async().method) assert not is_async_callable(Sync().method) -def test_async_object_call(): +def test_async_object_call() -> None: class Async: - async def __call__(self): + async def __call__(self) -> None: ... # pragma: no cover class Sync: - def __call__(self): + def __call__(self) -> None: ... # pragma: no cover assert is_async_callable(Async()) assert not is_async_callable(Sync()) -def test_async_partial_object_call(): +def test_async_partial_object_call() -> None: class Async: - async def __call__(self, a, b): + async def __call__( + self, + a: Any, + b: Any, + ) -> None: ... # pragma: no cover class Sync: - def __call__(self, a, b): + def __call__( + self, + a: Any, + b: Any, + ) -> None: ... # pragma: no cover partial = functools.partial(Async(), 1) assert is_async_callable(partial) - partial = functools.partial(Sync(), 1) + partial = functools.partial(Sync(), 1) # type: ignore assert not is_async_callable(partial) -def test_async_nested_partial(): - async def async_func(a, b): +def test_async_nested_partial() -> None: + async def async_func( + a: Any, + b: Any, + ) -> None: ... # pragma: no cover partial = functools.partial(async_func, b=2)