Skip to content

Commit d311f87

Browse files
committed
Fix pylint
* fix type annotations Signed-off-by: Aleksei Stepanov <[email protected]>
1 parent 7b4061f commit d311f87

File tree

7 files changed

+132
-27
lines changed

7 files changed

+132
-27
lines changed

threaded/_asynciotask.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def loop_getter_need_context(self) -> bool:
7474
return self.__loop_getter_need_context
7575

7676
def get_loop(self, *args: typing.Any, **kwargs: typing.Any) -> asyncio.AbstractEventLoop:
77-
"""Get event loop in decorator class."""
77+
"""Get event loop in decorator class.
78+
79+
:return: event loop if available or getter available
80+
:rtype: Optional[asyncio.AbstractEventLoop]
81+
"""
7882
if callable(self.loop_getter):
7983
if self.loop_getter_need_context:
8084
return self.loop_getter(*args, **kwargs)
@@ -94,6 +98,11 @@ def _get_function_wrapper(
9498
# noinspection PyMissingOrEmptyDocstring
9599
@functools.wraps(func)
96100
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> "asyncio.Task[typing.Any]":
101+
"""Function wrapper.
102+
103+
:return: asyncio.Task
104+
:rtype: asyncio.Task[Any]
105+
"""
97106
loop = self.get_loop(*args, **kwargs)
98107
return loop.create_task(func(*args, **kwargs))
99108

@@ -104,11 +113,19 @@ def __call__( # pylint: disable=useless-super-delegation
104113
*args: typing.Union[typing.Callable[..., "typing.Awaitable[typing.Any]"], typing.Any],
105114
**kwargs: typing.Any,
106115
) -> typing.Union["asyncio.Task[typing.Any]", typing.Callable[..., "asyncio.Task[typing.Any]"]]:
107-
"""Callable instance."""
116+
"""Callable instance.
117+
118+
:return: asyncio.Task or getter
119+
:rtype: Union[asyncio.Task[Any], Callable[..., asyncio.Task[Any]]]
120+
"""
108121
return super().__call__(*args, **kwargs) # type: ignore
109122

110123
def __repr__(self) -> str:
111-
"""For debug purposes."""
124+
"""For debug purposes.
125+
126+
:return: repr info
127+
:rtype: str
128+
"""
112129
return (
113130
f"<{self.__class__.__name__}("
114131
f"{self._func!r}, "

threaded/_asynciotask.pyx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ cdef class AsyncIOTask(class_decorator.BaseDecorator):
5555
self.loop_getter_need_context = loop_getter_need_context
5656

5757
def get_loop(self, *args, **kwargs): # type: (typing.Any, typing.Any) -> asyncio.AbstractEventLoop
58-
"""Get event loop in decorator class."""
58+
"""Get event loop in decorator class.
59+
60+
:return: event loop if available or getter available
61+
:rtype: Optional[asyncio.AbstractEventLoop]
62+
"""
5963
if callable(self.loop_getter):
6064
if self.loop_getter_need_context:
6165
return self.loop_getter(*args, **kwargs)
@@ -75,6 +79,11 @@ cdef class AsyncIOTask(class_decorator.BaseDecorator):
7579
# noinspection PyMissingOrEmptyDocstring
7680
@functools.wraps(func)
7781
def wrapper(*args, **kwargs): # type: (typing.Any, typing.Any) -> asyncio.Task
82+
"""Function wrapper.
83+
84+
:return: asyncio.Task
85+
:rtype: asyncio.Task[Any]
86+
"""
7887
loop = self.get_loop(*args, **kwargs)
7988
return loop.create_task(func(*args, **kwargs))
8089

@@ -83,11 +92,19 @@ cdef class AsyncIOTask(class_decorator.BaseDecorator):
8392
def __call__( # pylint: disable=useless-super-delegation
8493
self, *args: typing.Union[typing.Callable[..., "typing.Awaitable"], typing.Any], **kwargs: typing.Any
8594
) -> typing.Union[asyncio.Task, typing.Callable[..., asyncio.Task]]:
86-
"""Callable instance."""
95+
"""Callable instance.
96+
97+
:return: asyncio.Task or getter
98+
:rtype: Union[asyncio.Task[Any], Callable[..., asyncio.Task[Any]]]
99+
"""
87100
return super().__call__(*args, **kwargs) # type: ignore
88101

89102
def __repr__(self) -> str:
90-
"""For debug purposes."""
103+
"""For debug purposes.
104+
105+
:return: repr info
106+
:rtype: str
107+
"""
91108
return (
92109
f"<{self.__class__.__name__}("
93110
f"{self._func!r}, "

threaded/_threaded.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ def started(self) -> bool:
8686
return self.__started
8787

8888
def __repr__(self) -> str: # pragma: no cover
89-
"""For debug purposes."""
89+
"""For debug purposes.
90+
91+
:return: repr data
92+
:rtype: str
93+
"""
9094
return f"{self.__class__.__name__}(name={self.name!r}, daemon={self.daemon!r}, started={self.started!r}, )"
9195

9296
def _get_function_wrapper(
@@ -107,6 +111,11 @@ def _get_function_wrapper(
107111
# noinspection PyMissingOrEmptyDocstring
108112
@functools.wraps(prepared)
109113
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> threading.Thread:
114+
"""Thread getter.
115+
116+
:return: Thread object
117+
:rtype: threading.Thread
118+
"""
110119
thread = threading.Thread(target=prepared, name=name, args=args, kwargs=kwargs, daemon=self.daemon)
111120
if self.started:
112121
thread.start()
@@ -119,7 +128,11 @@ def __call__( # pylint: disable=useless-super-delegation
119128
*args: typing.Union[typing.Callable[..., typing.Union["typing.Awaitable[typing.Any]", typing.Any]], typing.Any],
120129
**kwargs: typing.Any,
121130
) -> typing.Union[threading.Thread, typing.Callable[..., threading.Thread]]:
122-
"""Executable instance."""
131+
"""Executable instance.
132+
133+
:return: Thread object or Thread getter
134+
:rtype: Union[threading.Thread, Callable[..., threading.Thread]]
135+
"""
123136
return super().__call__(*args, **kwargs) # type: ignore
124137

125138

threaded/_threaded.pyx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ cdef class Threaded(class_decorator.BaseDecorator):
6262
super().__init__(func=func)
6363

6464
def __repr__(self) -> str: # pragma: no cover
65-
"""For debug purposes."""
65+
"""For debug purposes.
66+
67+
:return: repr data
68+
:rtype: str
69+
"""
6670
return f"{self.__class__.__name__}(name={self.name!r}, daemon={self.daemon!r}, started={self.started!r}, )"
6771

6872
def _get_function_wrapper(
@@ -83,6 +87,11 @@ cdef class Threaded(class_decorator.BaseDecorator):
8387
# noinspection PyMissingOrEmptyDocstring
8488
@functools.wraps(prepared)
8589
def wrapper(*args, **kwargs): # type: (typing.Any, typing.Any) -> threading.Thread
90+
"""Thread getter.
91+
92+
:return: Thread object
93+
:rtype: threading.Thread
94+
"""
8695
thread = threading.Thread(target=prepared, name=name, args=args, kwargs=kwargs, daemon=self.daemon)
8796
if self.started:
8897
thread.start()
@@ -95,7 +104,11 @@ cdef class Threaded(class_decorator.BaseDecorator):
95104
*args: typing.Union[typing.Callable[..., typing.Union["typing.Awaitable", typing.Any]], typing.Any],
96105
**kwargs: typing.Any
97106
) -> typing.Union[threading.Thread, typing.Callable[..., threading.Thread]]:
98-
"""Executable instance."""
107+
"""Executable instance.
108+
109+
:return: Thread object or Thread getter
110+
:rtype: Union[threading.Thread, Callable[..., threading.Thread]]
111+
"""
99112
return super().__call__(*args, **kwargs) # type: ignore
100113

101114

threaded/_threadpooled.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ def loop_getter_need_context(self) -> bool:
113113
return self.__loop_getter_need_context
114114

115115
def _get_loop(self, *args: typing.Any, **kwargs: typing.Any) -> typing.Optional[asyncio.AbstractEventLoop]:
116-
"""Get event loop in decorator class."""
116+
"""Get event loop in decorator class.
117+
118+
:return: event loop if available or getter available
119+
:rtype: Optional[asyncio.AbstractEventLoop]
120+
"""
117121
if callable(self.loop_getter):
118122
if self.loop_getter_need_context:
119123
return self.loop_getter(*args, **kwargs) # pylint: disable=not-callable
@@ -128,19 +132,20 @@ def _get_function_wrapper(
128132
:param func: Wrapped function
129133
:type func: typing.Callable
130134
:return: wrapped coroutine or function
131-
:rtype: typing.Callable[..., typing.Union[typing.Awaitable, concurrent.futures.Future]]
135+
:rtype: Callable[..., Union[Awaitable, concurrent.futures.Future]]
132136
"""
133137
prepared = self._await_if_required(func)
134138

135139
# noinspection PyMissingOrEmptyDocstring
136140
@functools.wraps(prepared)
137141
def wrapper(
138142
*args: typing.Any, **kwargs: typing.Any
139-
) -> typing.Union[
140-
"concurrent.futures.Future[typing.Any]",
141-
"typing.Awaitable[typing.Any]",
142-
typing.Callable[..., "typing.Union[concurrent.futures.Future[typing.Any], typing.Awaitable[typing.Any]]"],
143-
]:
143+
) -> typing.Union["concurrent.futures.Future[typing.Any]", "typing.Awaitable[typing.Any]",]:
144+
"""Main function wrapper.
145+
146+
:return: coroutine or function
147+
:rtype: Union[Awaitable, concurrent.futures.Future]
148+
"""
144149
loop: typing.Optional[asyncio.AbstractEventLoop] = self._get_loop(*args, **kwargs)
145150

146151
if loop is None:
@@ -159,11 +164,19 @@ def __call__( # pylint: disable=useless-super-delegation
159164
"typing.Awaitable[typing.Any]",
160165
typing.Callable[..., "typing.Union[concurrent.futures.Future[typing.Any], typing.Awaitable[typing.Any]]"],
161166
]:
162-
"""Callable instance."""
167+
"""Callable instance.
168+
169+
:return: Future, Awaitable or it's getter (depends of decoration way and asyncio.Loop provided)
170+
:rtype: Union[concurrent.futures.Future[Any], Awaitable[Any] Callable[..., ...]]
171+
"""
163172
return super().__call__(*args, **kwargs) # type: ignore
164173

165174
def __repr__(self) -> str: # pragma: no cover
166-
"""For debug purposes."""
175+
"""For debug purposes.
176+
177+
:return: repr info
178+
:rtype: str
179+
"""
167180
return (
168181
f"<{self.__class__.__name__}("
169182
f"{self._func!r}, "

threaded/class_decorator.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ def __call__(
109109
*args: typing.Union[typing.Callable[..., typing.Union["typing.Awaitable[typing.Any]", typing.Any]], typing.Any],
110110
**kwargs: typing.Any,
111111
) -> typing.Any:
112-
"""Main decorator getter."""
112+
"""Main decorator getter.
113+
114+
:return: result of decorated function or result getter
115+
:rtype: Any
116+
"""
113117
l_args: typing.List[typing.Any] = list(args)
114118

115119
if self._func:
@@ -126,11 +130,19 @@ def __call__(
126130
def _await_if_required(
127131
target: typing.Callable[..., typing.Union["typing.Awaitable[typing.Any]", typing.Any]]
128132
) -> typing.Callable[..., typing.Any]:
129-
"""Await result if coroutine was returned."""
133+
"""Await result if coroutine was returned.
134+
135+
:return: function, which will await for result if it's required
136+
:rtype: Callable[..., Any]
137+
"""
130138

131139
@functools.wraps(target)
132140
def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Any:
133-
"""Decorator/wrapper."""
141+
"""Decorator/wrapper.
142+
143+
:return: target execution result (awaited if needed)
144+
:rtype: Any
145+
"""
134146
result = target(*args, **kwargs)
135147
if asyncio.iscoroutine(result):
136148
loop = asyncio.new_event_loop()
@@ -141,7 +153,11 @@ def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Any:
141153
return wrapper
142154

143155
def __repr__(self) -> str:
144-
"""For debug purposes."""
156+
"""For debug purposes.
157+
158+
:return: repr info
159+
:rtype: str
160+
"""
145161
return f"<{self.__class__.__name__}({self.__func!r}) at 0x{id(self):X}>" # pragma: no cover
146162

147163

threaded/class_decorator.pyx

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ cdef class BaseDecorator:
5252
raise NotImplementedError() # pragma: no cover
5353

5454
def __call__(self, *args: typing.Union[typing.Callable, typing.Any], **kwargs: typing.Any) -> typing.Any:
55-
"""Main decorator getter."""
55+
"""Main decorator getter.
56+
57+
:return: result of decorated function or result getter
58+
:rtype: Any
59+
"""
5660
cdef list l_args = list(args)
5761

5862
if self._func:
@@ -66,18 +70,30 @@ cdef class BaseDecorator:
6670
return wrapper
6771

6872
def __repr__(self) -> str:
69-
"""For debug purposes."""
73+
"""For debug purposes.
74+
75+
:return: repr info
76+
:rtype: str
77+
"""
7078
return f"<{self.__class__.__name__}({self._func!r}) at 0x{id(self):X}>" # pragma: no cover
7179

7280
@staticmethod
7381
def _await_if_required(
7482
target: typing.Callable[..., typing.Union["typing.Awaitable", typing.Any]]
7583
) -> typing.Callable[..., typing.Any]:
76-
"""Await result if coroutine was returned."""
84+
"""Await result if coroutine was returned.
85+
86+
:return: function, which will await for result if it's required
87+
:rtype: Callable[..., Any]
88+
"""
7789

7890
@functools.wraps(target)
7991
def wrapper(*args, **kwargs): # type: (typing.Any, typing.Any) -> typing.Any
80-
"""Decorator/wrapper."""
92+
"""Decorator/wrapper.
93+
94+
:return: target execution result (awaited if needed)
95+
:rtype: Any
96+
"""
8197
result = target(*args, **kwargs)
8298
if asyncio.iscoroutine(result):
8399
loop = asyncio.new_event_loop()

0 commit comments

Comments
 (0)