Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CI_REQUIREMENTS.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
typing >= 3.6 ; python_version < "3.8"
mock; python_version == "2.7"
futures>=3.1; python_version == "2.7"
greenlet <= 0.4.13
gevent >= 1.2, <1.3.0 ; platform_python_implementation == "PyPy"
gevent >= 1.2 ; platform_python_implementation != "PyPy"
2 changes: 1 addition & 1 deletion threaded/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
try: # pragma: no cover
from ._gthreadpooled2 import GThreadPooled, gthreadpooled
except ImportError: # pragma: no cover
GThreadPooled = gthreadpooled = None # type: ignore
GThreadPooled = gthreadpooled = None
# pylint: enable=no-name-in-module


Expand Down
2 changes: 1 addition & 1 deletion threaded/_base_gthreadpooled.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BaseGThreadPooled(_base_threaded.APIPooled):
# pylint: disable=arguments-differ
@classmethod
def configure(
cls,
cls, # type: typing.Type[BaseGThreadPooled]
max_workers=None, # type: typing.Optional[int]
hub=None # type: typing.Optional[gevent.hub.Hub]
): # type: (...) -> None
Expand Down
2 changes: 1 addition & 1 deletion threaded/_base_gthreadpooled.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ from . import _base_threaded
class BaseGThreadPooled(_base_threaded.APIPooled):
@classmethod
def configure(
cls,
cls: typing.Type[BaseGThreadPooled],
max_workers: typing.Optional[int]=...,
hub: typing.Optional[gevent.hub.Hub]=...
) -> None: ...
Expand Down
11 changes: 6 additions & 5 deletions threaded/_base_threaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from __future__ import absolute_import

import abc
# noinspection PyCompatibility
import concurrent.futures
import threading
Expand Down Expand Up @@ -43,7 +44,7 @@ def cpu_count(): # type: () -> int
)


class APIPooled(_class_decorator.BaseDecorator):
class APIPooled(six.with_metaclass(abc.ABCMeta, _class_decorator.BaseDecorator)):
"""API description for pooled."""

__slots__ = ()
Expand All @@ -52,7 +53,7 @@ class APIPooled(_class_decorator.BaseDecorator):

@classmethod
def configure(
cls,
cls, # type: typing.Type[APIPooled]
max_workers=None, # type: typing.Optional[int]
): # type: (...) -> None
"""Pool executor create and configure.
Expand All @@ -63,7 +64,7 @@ def configure(
raise NotImplementedError() # pragma: no cover

@classmethod
def shutdown(cls): # type: () -> None
def shutdown(cls): # type: (typing.Type[APIPooled]) -> None
"""Shutdown executor."""
raise NotImplementedError() # pragma: no cover

Expand All @@ -82,7 +83,7 @@ class BasePooled(APIPooled):

@classmethod
def configure(
cls,
cls, # type: typing.Type[BasePooled]
max_workers=None, # type: typing.Optional[int]
): # type: (...) -> None
"""Pool executor create and configure.
Expand All @@ -100,7 +101,7 @@ def configure(
)

@classmethod
def shutdown(cls): # type: () -> None
def shutdown(cls): # type: (typing.Type[BasePooled]) -> None
"""Shutdown executor."""
if cls.__executor is not None:
cls.__executor.shutdown()
Expand Down
11 changes: 6 additions & 5 deletions threaded/_base_threaded.pyi
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import abc
import concurrent.futures
import threading
import typing
from . import _class_decorator

def cpu_count() -> int: ...

class APIPooled(_class_decorator.BaseDecorator):
class APIPooled(_class_decorator.BaseDecorator, metaclass=abc.ABCMeta):
@classmethod
def configure(cls, max_workers: typing.Optional[int]=...) -> None: ...
def configure(cls: typing.Type[APIPooled], max_workers: typing.Optional[int]=...) -> None: ...

@classmethod
def shutdown(cls) -> None: ...
def shutdown(cls: typing.Type[APIPooled]) -> None: ...

@property
def executor(self) -> typing.Any: ...

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

@classmethod
def shutdown(cls) -> None: ...
def shutdown(cls: typing.Type[BasePooled]) -> None: ...

@property
def executor(self) -> ThreadPoolExecutor: ...
Expand Down
7 changes: 3 additions & 4 deletions threaded/_class_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@

import abc
import functools
import sys
import typing # noqa # pylint: disable=unused-import

PY3 = sys.version_info[:2] > (3, 0) # type: bool
import six


class BaseDecorator(object):
class BaseDecorator(six.with_metaclass(abc.ABCMeta, object)):
"""Base class for decorators.

Implements wrapping and __call__, wrapper getter is abstract.
Expand Down Expand Up @@ -81,7 +80,7 @@ def __init__(
self.__func = func # type: typing.Optional[typing.Callable]
if self.__func is not None:
functools.update_wrapper(self, self.__func)
if not PY3: # pragma: no cover
if not six.PY3: # pragma: no cover
self.__wrapped__ = self.__func # type: typing.Callable
# pylint: enable=assigning-non-slot
# noinspection PyArgumentList
Expand Down
3 changes: 1 addition & 2 deletions threaded/_class_decorator.pyi
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import abc
import typing

PY3: bool

class BaseDecorator:
class BaseDecorator(object, metaclass=abc.ABCMeta):
__wrapped__: typing.Optional[typing.Callable] = ...
def __init__(self, func: typing.Optional[typing.Callable]=...) -> None: ...

Expand Down
22 changes: 3 additions & 19 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
import typing # noqa # pylint: disable=unused-import

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

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


# 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
def gthreadpooled(
func=None # type: typing.Optional[typing.Callable]
): # type: (...) -> typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]
"""Post function to gevent.threadpool.ThreadPool.
Expand All @@ -66,4 +50,4 @@ def gthreadpooled( # noqa: F811
if func is None:
return GThreadPooled(func=func)
return GThreadPooled(func=None)(func)
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter, function-redefined
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter
7 changes: 6 additions & 1 deletion threaded/_gthreadpooled2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ from . import _base_gthreadpooled

class GThreadPooled(_base_gthreadpooled.BaseGThreadPooled): ...

def gthreadpooled(func: typing.Optional[typing.Callable]=...) -> typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]: ...

@typing.overload
def gthreadpooled(func: typing.Callable) -> typing.Callable[..., gevent.event.AsyncResult]: ...

@typing.overload
def gthreadpooled(func: None=...) -> GThreadPooled: ...
20 changes: 2 additions & 18 deletions threaded/_gthreadpooled3.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,8 @@ def wrapper(
return wrapper


# 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
def gthreadpooled(
func: typing.Optional[typing.Callable] = None
) -> typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]:
"""Post function to gevent.threadpool.ThreadPool.
Expand All @@ -93,4 +77,4 @@ def gthreadpooled( # noqa: F811
if func is None:
return GThreadPooled(func=func)
return GThreadPooled(func=None)(func)
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter, function-redefined
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter
7 changes: 6 additions & 1 deletion threaded/_gthreadpooled3.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ from . import _base_gthreadpooled

class GThreadPooled(_base_gthreadpooled.BaseGThreadPooled): ...

def gthreadpooled(func: typing.Optional[typing.Callable]=...) -> typing.Union[GThreadPooled, typing.Callable[..., gevent.event.AsyncResult]]: ...

@typing.overload
def gthreadpooled(func: typing.Callable) -> typing.Callable[..., gevent.event.AsyncResult]: ...

@typing.overload
def gthreadpooled(func: None=...) -> GThreadPooled: ...
4 changes: 2 additions & 2 deletions threaded/_py3_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@


def get_loop(
self,
*args, **kwargs
self: typing.Any,
*args: typing.Tuple, **kwargs: typing.Dict
) -> typing.Optional[asyncio.AbstractEventLoop]:
"""Get event loop in decorator class."""
if callable(self.loop_getter):
Expand Down
2 changes: 1 addition & 1 deletion threaded/_py3_helpers.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import asyncio
import typing

def get_loop(self, *args, **kwargs) -> typing.Optional[asyncio.AbstractEventLoop]: ...
def get_loop(self: typing.Any, *args: typing.Tuple, **kwargs: typing.Dict) -> typing.Optional[asyncio.AbstractEventLoop]: ...
def await_if_required(target: typing.Callable) -> typing.Callable[..., typing.Any]: ...
42 changes: 3 additions & 39 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
import typing # noqa # pylint: disable=unused-import

from . import _base_threaded

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


# 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
def threadpooled(
func=None # type: typing.Optional[typing.Callable]
): # type: (...) -> typing.Union[ThreadPooled, typing.Callable[..., concurrent.futures.Future]]
"""Post function to ThreadPoolExecutor.
Expand All @@ -76,27 +60,7 @@ def threadpooled( # noqa: F811
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
Expand All @@ -120,4 +84,4 @@ def threaded( # noqa: F811
)
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, function-redefined
# pylint: enable=unexpected-keyword-arg, no-value-for-parameter
20 changes: 14 additions & 6 deletions threaded/_threaded2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ from . import _base_threaded
class ThreadPooled(_base_threaded.BasePooled): ...
class Threaded(_base_threaded.BaseThreaded): ...

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, typing.Callable[..., threading.Thread]]: ...


@typing.overload
def threadpooled(func: typing.Callable) -> typing.Callable[..., concurrent.futures.Future]: ...

@typing.overload
def threadpooled(func: None=...) -> ThreadPooled: ...


@typing.overload
def threaded(name: typing.Callable, daemon: bool=..., started: bool=...) -> typing.Callable[..., threading.Thread]: ...

@typing.overload
def threaded(name: typing.Optional[str]=..., daemon: bool=..., started: bool=...) -> Threaded: ...
Loading