Skip to content

Commit

Permalink
Merge 632c481 into 38c439b
Browse files Browse the repository at this point in the history
  • Loading branch information
penguinolog committed May 17, 2018
2 parents 38c439b + 632c481 commit 85cda6f
Show file tree
Hide file tree
Showing 18 changed files with 200 additions and 45 deletions.
4 changes: 2 additions & 2 deletions CI_REQUIREMENTS.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
typing >= 3.6 ; python_version < "3.7"
mock; python_version == "2.7"
futures>=3.1; python_version == "2.7"
gevent >= 1.2 ; python_version < "3.7"
gevent >= 1.3.b1 ; python_version >= "3.7"
gevent >= 1.2, !=1.3.0 ; python_version < "3.7"
gevent >= 1.3 ; python_version >= "3.7"
2 changes: 1 addition & 1 deletion doc/source/asynciotask.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ API: Decorators: `AsyncIOTask`, `asynciotask`.
:type loop_getter: typing.Union[typing.Callable[..., asyncio.AbstractEventLoop], asyncio.AbstractEventLoop]
:param loop_getter_need_context: Loop getter requires function context
:type loop_getter_need_context: bool
:rtype: typing.Union[AsyncIOTask, asyncio.Task]
:rtype: typing.Union[AsyncIOTask, typing.Callable[..., asyncio.Task]]
2 changes: 1 addition & 1 deletion doc/source/gthreadpooled.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,4 @@ API: Decorators: `GThreadPooled`, `gthreadpooled`.

:param func: function to wrap
:type func: typing.Optional[typing.Callable]
:rtype: typing.Union[GThreadPooled, gevent.event.AsyncResult]
:rtype: typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]
2 changes: 1 addition & 1 deletion doc/source/threaded.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ API: Decorators: `Threaded` class and `threaded` function.
:type daemon: bool
:param started: Return started thread
:type started: bool
:rtype: typing.Union[Threaded, threading.Thread]
:rtype: typing.Union[Threaded, typing.Callable[..., threading.Thread]]
2 changes: 1 addition & 1 deletion doc/source/threadpooled.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ API: Decorators: `ThreadPooled`, `threadpooled`.
:type loop_getter: typing.Union[None, typing.Callable[..., asyncio.AbstractEventLoop], asyncio.AbstractEventLoop]
:param loop_getter_need_context: Loop getter requires function context
:type loop_getter_need_context: bool
:rtype: typing.Union[ThreadPooled, concurrent.futures.Future, asyncio.Task]
:rtype: typing.Union[ThreadPooled, typing.Callable[..., typing.Union[concurrent.futures.Future, asyncio.Task]]]

Not exported, but public accessed data type:

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ def get_simple_vars_from_src(src):
'threaded': [
os.path.basename(filename)
for filename in glob.glob(os.path.join('threaded', '*.pyi'))
] + [
'py.typed'
],
},
)
Expand Down
4 changes: 2 additions & 2 deletions threaded/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
try: # pragma: no cover
from ._gthreadpooled3 import GThreadPooled, gthreadpooled
except ImportError: # pragma: no cover
GThreadPooled = gthreadpooled = None
GThreadPooled = gthreadpooled = None # type: ignore
else: # pragma: no cover
from ._threaded2 import (
ThreadPooled,
Expand All @@ -46,7 +46,7 @@
try: # pragma: no cover
from ._gthreadpooled2 import GThreadPooled, gthreadpooled
except ImportError: # pragma: no cover
GThreadPooled = gthreadpooled = None
GThreadPooled = gthreadpooled = None # type: ignore
# pylint: enable=no-name-in-module


Expand Down
6 changes: 1 addition & 5 deletions threaded/_base_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from __future__ import absolute_import

import abc
# noinspection PyCompatibility
import concurrent.futures
import threading
Expand Down Expand Up @@ -52,7 +51,6 @@ class APIPooled(_class_decorator.BaseDecorator):
__executor = None # type: typing.Optional[typing.Any]

@classmethod
@abc.abstractmethod
def configure(
cls,
max_workers=None, # type: typing.Optional[int]
Expand All @@ -65,13 +63,11 @@ def configure(
raise NotImplementedError() # pragma: no cover

@classmethod
@abc.abstractmethod
def shutdown(cls): # type: () -> None
"""Shutdown executor."""
raise NotImplementedError() # pragma: no cover

@property
@abc.abstractmethod
def executor(self): # type: () -> typing.Any
"""Executor instance."""
raise NotImplementedError() # pragma: no cover
Expand All @@ -87,7 +83,7 @@ class BasePooled(APIPooled):
@classmethod
def configure(
cls,
max_workers=None, # type: int
max_workers=None, # type: typing.Optional[int]
): # type: (...) -> None
"""Pool executor create and configure.
Expand Down
2 changes: 1 addition & 1 deletion threaded/_base_threaded.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class APIPooled(_class_decorator.BaseDecorator):

class BasePooled(APIPooled):
@classmethod
def configure(cls, max_workers: int=...) -> None: ...
def configure(cls, max_workers: typing.Optional[int]=...) -> None: ...

@classmethod
def shutdown(cls) -> None: ...
Expand Down
26 changes: 21 additions & 5 deletions threaded/_gthreadpooled2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from __future__ import absolute_import

import typing # noqa # pylint: disable=unused-import
import typing

import gevent.event # noqa # pylint: disable=unused-import

Expand All @@ -37,17 +37,33 @@ class GThreadPooled(_base_gthreadpooled.BaseGThreadPooled):
__slots__ = ()


# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
# pylint: disable=unused-argument, function-redefined
@typing.overload
def gthreadpooled(
func=None # type: None
): # type: (...) -> GThreadPooled
"""Post function to gevent.threadpool.ThreadPool."""


@typing.overload # noqa: F811
def gthreadpooled(
func # type: typing.Callable
): # type: (...) -> typing.Callable[..., gevent.event.AsyncResult]
"""Post function to gevent.threadpool.ThreadPool."""
# pylint: enable=unused-argument


# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
def gthreadpooled( # noqa: F811
func=None # type: typing.Optional[typing.Callable]
): # type: (...) -> typing.Union[GThreadPooled, gevent.event.AsyncResult]
): # type: (...) -> typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]
"""Post function to gevent.threadpool.ThreadPool.
:param func: function to wrap
:type func: typing.Optional[typing.Callable]
:rtype: typing.Union[GThreadPooled, gevent.event.AsyncResult]
:rtype: typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]
"""
if func is None:
return GThreadPooled(func=func)
return GThreadPooled(func=None)(func)
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter, function-redefined
2 changes: 1 addition & 1 deletion threaded/_gthreadpooled2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ from . import _base_gthreadpooled

class GThreadPooled(_base_gthreadpooled.BaseGThreadPooled): ...

def gthreadpooled(func: typing.Optional[typing.Callable]=...) -> typing.Union[GThreadPooled, gevent.event.AsyncResult]: ...
def gthreadpooled(func: typing.Optional[typing.Callable]=...) -> typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]: ...
24 changes: 20 additions & 4 deletions threaded/_gthreadpooled3.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,33 @@ def wrapper(
return wrapper


# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
# pylint: disable=unused-argument, function-redefined
@typing.overload
def gthreadpooled(
func=None # type: None
): # type: (...) -> GThreadPooled
"""Post function to gevent.threadpool.ThreadPool."""


@typing.overload # noqa: F811
def gthreadpooled(
func # type: typing.Callable
): # type: (...) -> typing.Callable[..., gevent.event.AsyncResult]
"""Post function to gevent.threadpool.ThreadPool."""
# pylint: enable=unused-argument


# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
def gthreadpooled( # noqa: F811
func: typing.Optional[typing.Callable] = None
) -> typing.Union[GThreadPooled, gevent.event.AsyncResult]:
) -> typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]:
"""Post function to gevent.threadpool.ThreadPool.
:param func: function to wrap
:type func: typing.Optional[typing.Callable]
:rtype: typing.Union[GThreadPooled, gevent.event.AsyncResult]
:rtype: typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]
"""
if func is None:
return GThreadPooled(func=func)
return GThreadPooled(func=None)(func)
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter, function-redefined
2 changes: 1 addition & 1 deletion threaded/_gthreadpooled3.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ from . import _base_gthreadpooled

class GThreadPooled(_base_gthreadpooled.BaseGThreadPooled): ...

def gthreadpooled(func: typing.Optional[typing.Callable]=...) -> typing.Union[GThreadPooled, gevent.event.AsyncResult]: ...
def gthreadpooled(func: typing.Optional[typing.Callable]=...) -> typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]: ...
50 changes: 43 additions & 7 deletions threaded/_threaded2.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import concurrent.futures # noqa # pylint: disable=unused-import
import threading # noqa # pylint: disable=unused-import
import typing # noqa # pylint: disable=unused-import
import typing

from . import _base_threaded

Expand All @@ -45,26 +45,62 @@ class Threaded(_base_threaded.BaseThreaded):
__slots__ = ()


# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
# pylint: disable=unused-argument, function-redefined
@typing.overload
def threadpooled(
func=None # type: None
): # type: (...) -> ThreadPooled
"""Post function to ThreadPoolExecutor."""


@typing.overload # noqa: F811
def threadpooled(
func # type: typing.Callable
): # type: (...) -> typing.Callable[..., concurrent.futures.Future]
"""Post function to ThreadPoolExecutor."""
# pylint: enable=unused-argument


# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
def threadpooled( # noqa: F811
func=None # type: typing.Optional[typing.Callable]
): # type: (...) -> typing.Union[ThreadPooled, concurrent.futures.Future]
): # type: (...) -> typing.Union[ThreadPooled, typing.Callable[..., concurrent.futures.Future]]
"""Post function to ThreadPoolExecutor.
:param func: function to wrap
:type func: typing.Optional[typing.Callable]
:rtype: typing.Union[ThreadPooled, concurrent.futures.Future]
:rtype: typing.Union[ThreadPooled, typing.Callable[..., concurrent.futures.Future]]
"""
if func is None:
return ThreadPooled(func=func)
return ThreadPooled(func=None)(func)


# pylint: disable=unused-argument
@typing.overload
def threaded(
name=None, # type: typing.Optional[str]
daemon=False, # type: bool
started=False # type: bool
): # type: (...) -> Threaded
"""Run function in separate thread."""


@typing.overload # noqa: F811
def threaded(
name, # type: typing.Callable
daemon=False, # type: bool
started=False # type: bool
): # type: (...) -> typing.Callable[..., threading.Thread]
"""Run function in separate thread."""
# pylint: enable=unused-argument


def threaded( # noqa: F811
name=None, # type: typing.Optional[typing.Union[str, typing.Callable]]
daemon=False, # type: bool
started=False # type: bool
): # type: (...) -> typing.Union[Threaded, threading.Thread]
): # type: (...) -> typing.Union[Threaded, typing.Callable[..., threading.Thread]]
"""Run function in separate thread.
:param name: New thread name.
Expand All @@ -75,7 +111,7 @@ def threaded(
:type daemon: bool
:param started: Return started thread
:type started: bool
:rtype: typing.Union[Threaded, threading.Thread]
:rtype: typing.Union[Threaded, typing.Callable[..., threading.Thread]]
"""
if callable(name):
func, name = (
Expand All @@ -84,4 +120,4 @@ def threaded(
)
return Threaded(name=name, daemon=daemon, started=started)(func)
return Threaded(name=name, daemon=daemon, started=started)
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter, function-redefined
4 changes: 2 additions & 2 deletions threaded/_threaded2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ from . import _base_threaded
class ThreadPooled(_base_threaded.BasePooled): ...
class Threaded(_base_threaded.BaseThreaded): ...

def threadpooled(func: typing.Optional[typing.Callable]=...) -> typing.Union[ThreadPooled, concurrent.futures.Future]: ...
def threadpooled(func: typing.Optional[typing.Callable]=...) -> typing.Union[ThreadPooled, typing.Callable[..., concurrent.futures.Future]]: ...

def threaded(
name: typing.Optional[typing.Union[str, typing.Callable]]=...,
daemon: bool=...,
started: bool=...
) -> typing.Union[Threaded, threading.Thread]: ...
) -> typing.Union[Threaded, typing.Callable[..., threading.Thread]]: ...
Loading

0 comments on commit 85cda6f

Please sign in to comment.