Skip to content

Commit

Permalink
make valid *args **kwargs type hints (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
penguinolog committed Aug 28, 2018
1 parent 752a475 commit 470899d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 35 deletions.
8 changes: 1 addition & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import collections
from distutils.command import build_ext
import distutils.errors
import glob
import os.path
import shutil
import sys
Expand Down Expand Up @@ -263,12 +262,7 @@ def get_simple_vars_from_src(src):
},
install_requires=required,
package_data={
'threaded': [
os.path.basename(filename)
for filename in glob.glob(os.path.join('threaded', '*.pyi'))
] + [
'py.typed'
],
'threaded': ['py.typed'],
},
)
if cythonize is not None:
Expand Down
14 changes: 7 additions & 7 deletions threaded/_asynciotask.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def loop_getter_need_context(self) -> bool:

def get_loop(
self,
*args, # type: typing.Tuple
**kwargs # type: typing.Dict
*args, # type: typing.Any
**kwargs # type: typing.Any
) -> asyncio.AbstractEventLoop:
"""Get event loop in decorator class."""
if callable(self.loop_getter):
Expand All @@ -110,19 +110,19 @@ def _get_function_wrapper(
# noinspection PyMissingOrEmptyDocstring
@functools.wraps(func)
def wrapper(
*args, # type: typing.Tuple
**kwargs # type: typing.Dict
*args, # type: typing.Any
**kwargs # type: typing.Any
) -> asyncio.Task:
loop = self.get_loop(*args, **kwargs) # type: ignore
loop = self.get_loop(*args, **kwargs)
return loop.create_task(func(*args, **kwargs))

# pylint: enable=missing-docstring
return wrapper

def __call__( # pylint: disable=useless-super-delegation
self,
*args: typing.Union[typing.Tuple, typing.Callable],
**kwargs: typing.Dict
*args: typing.Union[typing.Callable, typing.Any],
**kwargs: typing.Any
) -> typing.Union[asyncio.Task, typing.Callable[..., asyncio.Task]]:
"""Callable instance."""
return super(AsyncIOTask, self).__call__(*args, **kwargs) # type: ignore
Expand Down
10 changes: 5 additions & 5 deletions threaded/_class_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ def _get_function_wrapper(

def __call__(
self,
*args: typing.Union[typing.Tuple, typing.Callable],
**kwargs: typing.Dict
*args: typing.Union[typing.Callable, typing.Any],
**kwargs: typing.Any
) -> typing.Any:
"""Main decorator getter."""
l_args = list(args)

if self._func:
wrapped = self._func # type: typing.Callable
else:
wrapped = l_args.pop(0) # type: ignore
wrapped = l_args.pop(0)

wrapper = self._get_function_wrapper(wrapped)
if self.__func:
Expand All @@ -126,8 +126,8 @@ def _await_if_required(target: typing.Callable) -> typing.Callable[..., typing.A
"""Await result if coroutine was returned."""
@functools.wraps(target)
def wrapper(
*args, # type: typing.Tuple
**kwargs # type: typing.Dict
*args, # type: typing.Any
**kwargs # type: typing.Any
) -> typing.Any:
"""Decorator/wrapper."""
result = target(*args, **kwargs)
Expand Down
10 changes: 5 additions & 5 deletions threaded/_gthreadpooled.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def _get_function_wrapper(
# noinspection PyMissingOrEmptyDocstring
@functools.wraps(prepared)
def wrapper(
*args, # type: typing.Tuple
**kwargs # type: typing.Dict
*args, # type: typing.Any
**kwargs # type: typing.Any
) -> gevent.event.AsyncResult:
return self.executor.spawn(prepared, *args, **kwargs)

Expand All @@ -118,11 +118,11 @@ def wrapper(

def __call__( # pylint: disable=useless-super-delegation
self,
*args: typing.Union[typing.Tuple, typing.Callable],
**kwargs: typing.Dict
*args: typing.Union[typing.Callable, typing.Any],
**kwargs: typing.Any
) -> typing.Union[gevent.event.AsyncResult, typing.Callable[..., gevent.event.AsyncResult]]:
"""Callable instance."""
return super(GThreadPooled, self).__call__(*args, **kwargs) # type: ignore
return super(GThreadPooled, self).__call__(*args, **kwargs)


# pylint: disable=function-redefined, unused-argument
Expand Down
8 changes: 4 additions & 4 deletions threaded/_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def _get_function_wrapper(
# noinspection PyMissingOrEmptyDocstring
@functools.wraps(prepared)
def wrapper(
*args, # type: typing.Tuple
**kwargs # type: typing.Dict
*args, # type: typing.Any
**kwargs # type: typing.Any
) -> threading.Thread:
thread = threading.Thread(
target=prepared,
Expand All @@ -146,8 +146,8 @@ def wrapper(

def __call__( # pylint: disable=useless-super-delegation
self,
*args: typing.Union[typing.Tuple, typing.Callable],
**kwargs: typing.Dict
*args: typing.Union[typing.Callable, typing.Any],
**kwargs: typing.Any
) -> typing.Union[threading.Thread, typing.Callable[..., threading.Thread]]:
"""Executable instance."""
return super(Threaded, self).__call__(*args, **kwargs) # type: ignore
Expand Down
14 changes: 7 additions & 7 deletions threaded/_threadpooled.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ def loop_getter_need_context(self) -> bool:

def _get_loop(
self,
*args: typing.Tuple,
**kwargs: typing.Dict
*args: typing.Any,
**kwargs: typing.Any
) -> typing.Optional[asyncio.AbstractEventLoop]:
"""Get event loop in decorator class."""
if callable(self.loop_getter):
Expand All @@ -160,13 +160,13 @@ def _get_function_wrapper(
# noinspection PyMissingOrEmptyDocstring
@functools.wraps(prepared)
def wrapper(
*args: typing.Tuple,
**kwargs: typing.Dict
*args: typing.Any,
**kwargs: typing.Any
) -> typing.Union[
typing.Awaitable, concurrent.futures.Future,
typing.Callable[..., typing.Union[typing.Awaitable, concurrent.futures.Future]]
]:
loop = self._get_loop(*args, **kwargs) # type: ignore
loop = self._get_loop(*args, **kwargs)

if loop is None:
return self.executor.submit(prepared, *args, **kwargs)
Expand All @@ -184,8 +184,8 @@ def wrapper(

def __call__( # pylint: disable=useless-super-delegation
self,
*args: typing.Union[typing.Tuple, typing.Callable],
**kwargs: typing.Dict
*args: typing.Union[typing.Callable, typing.Any],
**kwargs: typing.Any
) -> typing.Union[
concurrent.futures.Future, typing.Awaitable,
typing.Callable[..., typing.Union[typing.Awaitable, concurrent.futures.Future]]
Expand Down

0 comments on commit 470899d

Please sign in to comment.