Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement PEP518 support, mass fix of type hints + add stubs #1

Merged
merged 1 commit into from
Apr 25, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.{py,ini}]
max_line_length = 79
max_line_length = 120

[*.{yml,rst}]
indent_size = 2
Expand Down
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ logging-modules=logging
[FORMAT]

# Maximum number of characters on a single line.
max-line-length=80
max-line-length=120

# Regexp for a line that is allowed to be longer than the limit.
ignore-long-lines=^\s*(# )?<?https?://\S+>?$
Expand Down
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: AsyncIOTask
:rtype: typing.Union[AsyncIOTask, 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: GThreadPooled
:rtype: typing.Union[GThreadPooled, gevent.event.AsyncResult]
12 changes: 9 additions & 3 deletions doc/source/threaded.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ API: Decorators: `Threaded` class and `threaded` function.
:param name: New thread name.
If callable: use as wrapped function.
If none: use wrapped function name.
:type name: typing.Union[None, str, typing.Callable[.., typing.Union[typing.Any, typing.Awaitable]]]
:type name: typing.Optional[typing.Union[str, typing.Callable[.., typing.Union[typing.Any, typing.Awaitable]]]]
:param daemon: Daemonize thread.
:type daemon: bool
:param started: Return started thread
Expand All @@ -28,7 +28,13 @@ API: Decorators: `Threaded` class and `threaded` function.
``typing.Optional[str]`` - New thread name. If none: use wrapped function name.

.. py:attribute:: started

``bool``

.. py:attribute:: daemon

``bool``

.. py:attribute:: _func

Wrapped function. Used for inheritance only.
Expand All @@ -47,9 +53,9 @@ API: Decorators: `Threaded` class and `threaded` function.
:param name: New thread name.
If callable: use as wrapped function.
If none: use wrapped function name.
:type name: typing.Union[None, str, typing.Callable[.., typing.Union[typing.Any, typing.Awaitable]]]
:type name: typing.Optional[typing.Union[str, typing.Callable[.., typing.Union[typing.Any, typing.Awaitable]]]]
:param daemon: Daemonize thread.
:type daemon: bool
:param started: Return started thread
:type started: bool
:rtype: Threaded
:rtype: typing.Union[Threaded, threading.Thread]
4 changes: 3 additions & 1 deletion doc/source/threadpooled.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ API: Decorators: `ThreadPooled`, `threadpooled`.

``ThreadPoolExecutor`` instance. Class-wide.

:rtype: ThreadPoolExecutor

.. py:attribute:: _func

``typing.Optional[typing.Callable[..., typing.Union[typing.Any, typing.Awaitable]]]``
Expand Down Expand Up @@ -84,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: ThreadPooled
:rtype: typing.Union[ThreadPooled, concurrent.futures.Future, asyncio.Task]

Not exported, but public accessed data type:

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
# Minimum requirements for the build system to execute.
# PEP 508 specifications for PEP 518.
requires = [
"setuptools > 20.2 ",
"wheel",
]
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import collections
from distutils.command import build_ext
import distutils.errors
import glob
import os.path
import shutil
import sys
Expand All @@ -32,7 +33,7 @@

import setuptools

PY3 = sys.version_info[:2] > (2, 7)
PY3 = sys.version_info[:2] > (2, 7) # type: bool

with open(
os.path.join(
Expand Down Expand Up @@ -258,6 +259,12 @@ 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'))
],
},
)
if PY3 and cythonize is not None:
setup_args['ext_modules'] = ext_modules
Expand Down
2 changes: 1 addition & 1 deletion threaded/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import sys

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

# pylint: disable=no-name-in-module
if PY3: # pragma: no cover
Expand Down
24 changes: 16 additions & 8 deletions threaded/_base_gthreadpooled.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

from __future__ import absolute_import

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

import gevent.threadpool
import six

Expand All @@ -31,15 +33,15 @@ class BaseGThreadPooled(_base_threaded.APIPooled):

__slots__ = ()

__executor = None
__executor = None # type: typing.Optional[gevent.threadpool.ThreadPool]

# pylint: disable=arguments-differ
@classmethod
def configure(
cls,
max_workers=None,
hub=None
):
max_workers=None, # type: typing.Optional[int]
hub=None # type: typing.Optional[gevent.hub.Hub]
): # type: (...) -> None
"""Pool executor create and configure.

:param max_workers: Maximum workers
Expand Down Expand Up @@ -67,7 +69,7 @@ def configure(
# pylint: enable=arguments-differ

@classmethod
def shutdown(cls):
def shutdown(cls): # type: () -> None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency I would use either () or (...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@classmethod and (cls) means, that no arguments accepted -> should use () in typing. (...) expect arguments accept.

"""Shutdown executor.

Due to not implemented method, set maxsize to 0 (do not accept new).
Expand All @@ -76,7 +78,7 @@ def shutdown(cls):
cls.__executor.kill()

@property
def executor(self):
def executor(self): # type: () -> gevent.threadpool.ThreadPool
"""Executor instance.

:rtype: gevent.threadpool.ThreadPool
Expand All @@ -85,7 +87,10 @@ def executor(self):
self.configure()
return self.__executor

def _get_function_wrapper(self, func):
def _get_function_wrapper(
self,
func # type: typing.Callable
): # type: (...) -> typing.Callable[..., gevent.event.AsyncResult]
"""Here should be constructed and returned real decorator.

:param func: Wrapped function
Expand All @@ -96,7 +101,10 @@ def _get_function_wrapper(self, func):
# pylint: disable=missing-docstring
# noinspection PyMissingOrEmptyDocstring
@six.wraps(func)
def wrapper(*args, **kwargs):
def wrapper(
*args,
**kwargs
): # type: (...) -> gevent.event.AsyncResult
return self.executor.spawn(func, *args, **kwargs)
# pylint: enable=missing-docstring
return wrapper
17 changes: 17 additions & 0 deletions threaded/_base_gthreadpooled.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import gevent.threadpool
import typing
from . import _base_threaded

class BaseGThreadPooled(_base_threaded.APIPooled):
@classmethod
def configure(
cls,
max_workers: typing.Optional[int]=...,
hub: typing.Optional[gevent.hub.Hub]=...
) -> None: ...

@classmethod
def shutdown(cls) -> None: ...

@property
def executor(self) -> gevent.threadpool.ThreadPool: ...