Skip to content

Commit 6e9e782

Browse files
authored
Make 4.0.0 Fix #15 (#28)
* Drop of *args * Update tests to deal with defaults * Fix blacklisted_exceptions type annotations * Remove additional garbage from sdist
1 parent f31146e commit 6e9e782

12 files changed

+318
-329
lines changed

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ global-exclude *.c
33
exclude Makefile
44
prune tools
55
exclude .travis.yml appveyor.yml
6-
exclude tox.ini
6+
exclude tox.ini pytest.ini .coveragerc
77
prune test
88
prune .github
99
prune docs

doc/source/logwrap.rst

+3-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ API: Decorators: `LogWrap` class and `logwrap` function.
3838
:param blacklisted_exceptions: list of exception,
3939
which should be re-raised without
4040
producing log record.
41-
:type blacklisted_exceptions: typing.Optional[typing.Iterable[Exception]]
41+
:type blacklisted_exceptions: typing.Optional[typing.Iterable[typing.Type[Exception]]]
4242
:param log_call_args: log call arguments before executing wrapped function.
4343
:type log_call_args: bool
4444
:param log_call_args_on_exc: log call arguments if exception raised.
@@ -48,6 +48,7 @@ API: Decorators: `LogWrap` class and `logwrap` function.
4848

4949
.. versionchanged:: 3.3.0 Extract func from log and do not use Union.
5050
.. versionchanged:: 3.3.0 Deprecation of `*args`
51+
.. versionchanged:: 4.0.0 Drop of *args
5152

5253
.. py:method:: pre_process_param(self, arg)
5354
@@ -88,7 +89,7 @@ API: Decorators: `LogWrap` class and `logwrap` function.
8889
``typing.List[str]``, modified via mutability
8990
.. py:attribute:: blacklisted_exceptions
9091
91-
``typing.List[Exception]``, modified via mutability
92+
``typing.List[typing.Type[Exception]]``, modified via mutability
9293
.. py:attribute:: log_call_args
9394
.. py:attribute:: log_call_args_on_exc
9495
.. py:attribute:: log_result_obj

logwrap/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
'bind_args_kwargs'
5757
)
5858

59-
__version__ = '3.3.1'
59+
__version__ = '4.0.0'
6060
__author__ = "Alexey Stepanov"
6161
__author_email__ = '[email protected]'
6262
__maintainers__ = {

logwrap/_log_wrap2.py

+46-61
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import logging
2727
import typing # noqa # pylint: disable=unused-import
28-
import warnings
2928

3029
import six
3130
# noinspection PyUnresolvedReferences
@@ -36,45 +35,24 @@
3635
__all__ = ('logwrap', 'LogWrap')
3736

3837

39-
def _apply_old_spec(*args, **kwargs): # type: (...) -> typing.Dict[str, typing.Any]
40-
# pylint: disable=unused-argument
41-
def old_spec(
42-
log=_log_wrap_shared.logger, # type: typing.Union[logging.Logger, typing.Callable]
38+
class LogWrap(_log_wrap_shared.BaseLogWrap):
39+
"""LogWrap."""
40+
41+
__slots__ = ()
42+
43+
def __init__(
44+
self,
45+
func=None, # type: typing.Optional[typing.Callable]
46+
log=_log_wrap_shared.logger, # type: logging.Logger
4347
log_level=logging.DEBUG, # type: int
4448
exc_level=logging.ERROR, # type: int
4549
max_indent=20, # type: int
4650
spec=None, # type: typing.Optional[typing.Callable]
4751
blacklisted_names=None, # type: typing.Optional[typing.List[str]]
48-
blacklisted_exceptions=None, # type: typing.Optional[typing.List[Exception]]
52+
blacklisted_exceptions=None, # type: typing.Optional[typing.List[typing.Type[Exception]]]
4953
log_call_args=True, # type: bool
5054
log_call_args_on_exc=True, # type: bool
5155
log_result_obj=True, # type: bool
52-
): # type: (...) -> None
53-
"""Old spec."""
54-
pass # pragma: no cover
55-
56-
# pylint: enable=unused-argument
57-
58-
sig = funcsigs.signature(old_spec) # type: funcsigs.Signature
59-
60-
final_kwargs = {
61-
parameter.name: parameter.value
62-
for parameter in _log_wrap_shared.bind_args_kwargs(sig, *args, **kwargs)
63-
} # type: typing.Dict[str, typing.Any]
64-
65-
return final_kwargs
66-
67-
68-
class LogWrap(_log_wrap_shared.BaseLogWrap):
69-
"""LogWrap."""
70-
71-
__slots__ = ()
72-
73-
def __init__( # pylint: disable=keyword-arg-before-vararg
74-
self,
75-
func=None, # type: typing.Optional[typing.Callable]
76-
*args,
77-
**kwargs
7856
): # type: (...) -> None
7957
"""Log function calls and return values.
8058
@@ -99,7 +77,7 @@ def __init__( # pylint: disable=keyword-arg-before-vararg
9977
:param blacklisted_names: Blacklisted argument names. Arguments with this names will be skipped in log.
10078
:type blacklisted_names: typing.Optional[typing.Iterable[str]]
10179
:param blacklisted_exceptions: list of exception, which should be re-raised without producing log record.
102-
:type blacklisted_exceptions: typing.Optional[typing.Iterable[Exception]]
80+
:type blacklisted_exceptions: typing.Optional[typing.Iterable[typing.Type[Exception]]]
10381
:param log_call_args: log call arguments before executing wrapped function.
10482
:type log_call_args: bool
10583
:param log_call_args_on_exc: log call arguments if exception raised.
@@ -109,18 +87,19 @@ def __init__( # pylint: disable=keyword-arg-before-vararg
10987
11088
.. versionchanged:: 3.3.0 Extract func from log and do not use Union.
11189
"""
112-
if isinstance(func, logging.Logger):
113-
args = (func,) + args
114-
func = None
115-
116-
if args:
117-
warnings.warn(
118-
'Logwrap should use keyword-only parameters starting from version 3.4.0\n'
119-
'After version 3.4.0 arguments list and order may be changed.',
120-
DeprecationWarning
121-
)
122-
123-
super(LogWrap, self).__init__(func=func, **_apply_old_spec(*args, **kwargs))
90+
super(LogWrap, self).__init__(
91+
func=func,
92+
log=log,
93+
log_level=log_level,
94+
exc_level=exc_level,
95+
max_indent=max_indent,
96+
spec=spec,
97+
blacklisted_names=blacklisted_names,
98+
blacklisted_exceptions=blacklisted_exceptions,
99+
log_call_args=log_call_args,
100+
log_call_args_on_exc=log_call_args_on_exc,
101+
log_result_obj=log_result_obj
102+
)
124103

125104
def _get_function_wrapper(
126105
self,
@@ -161,10 +140,18 @@ def wrapper(*args, **kwargs):
161140

162141

163142
# pylint: disable=unexpected-keyword-arg, no-value-for-parameter
164-
def logwrap( # pylint: disable=keyword-arg-before-vararg
143+
def logwrap(
165144
func=None, # type: typing.Optional[typing.Callable]
166-
*args,
167-
**kwargs
145+
log=_log_wrap_shared.logger, # type: logging.Logger
146+
log_level=logging.DEBUG, # type: int
147+
exc_level=logging.ERROR, # type: int
148+
max_indent=20, # type: int
149+
spec=None, # type: typing.Optional[typing.Callable]
150+
blacklisted_names=None, # type: typing.Optional[typing.List[str]]
151+
blacklisted_exceptions=None, # type: typing.Optional[typing.List[typing.Type[Exception]]]
152+
log_call_args=True, # type: bool
153+
log_call_args_on_exc=True, # type: bool
154+
log_result_obj=True, # type: bool
168155
): # type: (...) -> typing.Union[LogWrap, typing.Callable]
169156
"""Log function calls and return values.
170157
@@ -188,7 +175,7 @@ def logwrap( # pylint: disable=keyword-arg-before-vararg
188175
:param blacklisted_names: Blacklisted argument names. Arguments with this names will be skipped in log.
189176
:type blacklisted_names: typing.Optional[typing.List[str]]
190177
:param blacklisted_exceptions: list of exception, which should be re-raised without producing log record.
191-
:type blacklisted_exceptions: typing.Optional[typing.List[Exception]]
178+
:type blacklisted_exceptions: typing.Optional[typing.List[typing.Type[Exception]]]
192179
:param log_call_args: log call arguments before executing wrapped function.
193180
:type log_call_args: bool
194181
:param log_call_args_on_exc: log call arguments if exception raised.
@@ -200,19 +187,17 @@ def logwrap( # pylint: disable=keyword-arg-before-vararg
200187
201188
.. versionchanged:: 3.3.0 Extract func from log and do not use Union.
202189
"""
203-
if isinstance(func, logging.Logger):
204-
args = (func, ) + args
205-
func = None
206-
207-
if args:
208-
warnings.warn(
209-
'Logwrap should use keyword-only parameters starting from version 3.4.0\n'
210-
'After version 3.4.0 arguments list and order may be changed.',
211-
DeprecationWarning
212-
)
213-
214190
wrapper = LogWrap(
215-
**_apply_old_spec(*args, **kwargs)
191+
log=log,
192+
log_level=log_level,
193+
exc_level=exc_level,
194+
max_indent=max_indent,
195+
spec=spec,
196+
blacklisted_names=blacklisted_names,
197+
blacklisted_exceptions=blacklisted_exceptions,
198+
log_call_args=log_call_args,
199+
log_call_args_on_exc=log_call_args_on_exc,
200+
log_result_obj=log_result_obj
216201
)
217202
if func is not None:
218203
return wrapper(func)

logwrap/_log_wrap2.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class LogWrap(_log_wrap_shared.BaseLogWrap):
1515
max_indent: int=...,
1616
spec: typing.Optional[typing.Callable]=...,
1717
blacklisted_names: typing.Optional[typing.List[str]]=...,
18-
blacklisted_exceptions: typing.Optional[typing.List[Exception]]=...,
18+
blacklisted_exceptions: typing.Optional[typing.List[typing.Type[Exception]]]=...,
1919
log_call_args: bool=...,
2020
log_call_args_on_exc: bool=...,
2121
log_result_obj: bool=...
@@ -31,7 +31,7 @@ def logwrap(
3131
max_indent: int=...,
3232
spec: typing.Optional[typing.Callable]=...,
3333
blacklisted_names: typing.Optional[typing.List[str]]=...,
34-
blacklisted_exceptions: typing.Optional[typing.List[Exception]]=...,
34+
blacklisted_exceptions: typing.Optional[typing.List[typing.Type[Exception]]]=...,
3535
log_call_args: bool=...,
3636
log_call_args_on_exc: bool=...,
3737
log_result_obj: bool=...

0 commit comments

Comments
 (0)