Skip to content

Commit 03a7fc8

Browse files
Added missing annotations in _core.py file (#65)
* added missing annotations in _core.py file * removed unused typing imports, format code according to black
1 parent 01ab3f4 commit 03a7fc8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

asyncstdlib/_core.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
from inspect import iscoroutinefunction
22
from typing import (
3+
Any,
34
AsyncIterator,
5+
AsyncGenerator,
46
Iterable,
57
AsyncIterable,
68
Union,
79
Generic,
810
Optional,
911
Awaitable,
1012
Callable,
13+
Type,
1114
)
15+
from types import TracebackType
1216

1317
from ._typing import T, AnyIterable
1418

@@ -18,10 +22,10 @@ class Sentinel:
1822

1923
__slots__ = ("name",)
2024

21-
def __init__(self, name):
25+
def __init__(self, name: str):
2226
self.name = name
2327

24-
def __repr__(self):
28+
def __repr__(self) -> str:
2529
return self.name
2630

2731

@@ -67,7 +71,12 @@ async def __aenter__(self) -> AsyncIterator[T]:
6771
self._iterable = None
6872
return self._iterator
6973

70-
async def __aexit__(self, exc_type, exc_val, exc_tb) -> bool:
74+
async def __aexit__(
75+
self,
76+
exc_type: Optional[Type[BaseException]],
77+
exc_val: Optional[BaseException],
78+
exc_tb: Optional[TracebackType],
79+
) -> bool:
7180
try:
7281
aclose = self._iterator.aclose() # type: ignore
7382
except AttributeError:
@@ -77,7 +86,7 @@ async def __aexit__(self, exc_type, exc_val, exc_tb) -> bool:
7786
return False
7887

7988

80-
async def borrow(iterator: AsyncIterator):
89+
async def borrow(iterator: AsyncIterator[T]) -> AsyncGenerator[T, None]:
8190
"""Borrow an async iterator for iteration, preventing it from being closed"""
8291
async for item in iterator:
8392
yield item
@@ -102,7 +111,7 @@ def __init__(self, function: Union[Callable[..., T], Callable[..., Awaitable[T]]
102111
self.__wrapped__ = function
103112
self._async_call: Optional[Callable[..., Awaitable[T]]] = None
104113

105-
def __call__(self, *args, **kwargs) -> Awaitable[T]:
114+
def __call__(self, *args: Any, **kwargs: Any) -> Awaitable[T]:
106115
async_call = self._async_call
107116
if async_call is None:
108117
value = self.__wrapped__(*args, **kwargs)
@@ -121,7 +130,7 @@ async def await_value(value: T) -> T:
121130

122131

123132
def force_async(call: Callable[..., T]) -> Callable[..., Awaitable[T]]:
124-
async def async_wrapped(*args, **kwargs):
133+
async def async_wrapped(*args: Any, **kwargs: Any) -> T:
125134
return call(*args, **kwargs)
126135

127136
return async_wrapped

0 commit comments

Comments
 (0)