Skip to content

Commit 1f1c4d9

Browse files
committed
Pylint
1 parent 9c8f81f commit 1f1c4d9

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

logwrap/_alogwrap.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,32 +64,29 @@ def wrapper(*args, **kwargs):
6464

6565
try:
6666
if asyncio.iscoroutinefunction(func):
67-
self._logger.log(
68-
level=self.log_level,
69-
msg="Awaiting: \n{name!r}({arguments})".format(
70-
name=func.__name__,
71-
arguments=args_repr
72-
)
67+
self._make_calling_record(
68+
name=func.__name__,
69+
arguments=args_repr,
70+
method='Awaiting'
7371
)
7472
result = yield from func(*args, **kwargs)
7573
else:
76-
self._logger.log(
77-
level=self.log_level,
78-
msg="Calling: \n{name!r}({arguments})".format(
79-
name=func.__name__,
80-
arguments=args_repr
81-
)
74+
75+
self._make_calling_record(
76+
name=func.__name__,
77+
arguments=args_repr
8278
)
8379
result = func(*args, **kwargs)
8480
self._make_done_record(func.__name__, result)
8581
except BaseException as e:
8682
if isinstance(e, tuple(self.blacklisted_exceptions)):
8783
raise
84+
arguments = args_repr if self.log_call_args_on_exc else ''
8885
self._logger.log(
8986
level=self.exc_level,
9087
msg="Failed: \n{name!r}({arguments})".format(
9188
name=func.__name__,
92-
arguments=args_repr,
89+
arguments=arguments,
9390
),
9491
exc_info=True
9592
)
@@ -100,6 +97,7 @@ def wrapper(*args, **kwargs):
10097
return wrapper
10198

10299

100+
# pylint: disable=unexpected-keyword-arg
103101
def async_logwrap(
104102
log: logging.Logger=_log_wrap_shared.logger,
105103
log_level: int=logging.DEBUG,
@@ -154,3 +152,4 @@ def async_logwrap(
154152
log_call_args_on_exc=log_call_args_on_exc,
155153
log_result_obj=log_result_obj
156154
)
155+
# pylint: enable=unexpected-keyword-arg

logwrap/_log_wrap.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,24 +81,19 @@ def wrapper(*args, **kwargs):
8181
kwargs=kwargs,
8282
)
8383

84-
self._logger.log(
85-
level=self.log_level,
86-
msg="Calling: \n{name!r}({arguments})".format(
87-
name=func.__name__,
88-
arguments=args_repr
89-
)
90-
)
84+
self._make_calling_record(name=func.__name__, arguments=args_repr)
9185
try:
9286
result = func(*args, **kwargs)
9387
self._make_done_record(func.__name__, result)
9488
except BaseException as e:
9589
if isinstance(e, tuple(self.blacklisted_exceptions)):
9690
raise
91+
arguments = args_repr if self.log_call_args_on_exc else ''
9792
self._logger.log(
9893
level=self.exc_level,
9994
msg="Failed: \n{name!r}({arguments})".format(
10095
name=func.__name__,
101-
arguments=args_repr,
96+
arguments=arguments,
10297
),
10398
exc_info=True
10499
)
@@ -109,6 +104,7 @@ def wrapper(*args, **kwargs):
109104
return wrapper
110105

111106

107+
# pylint: disable=unexpected-keyword-arg
112108
def logwrap(
113109
log=_log_wrap_shared.logger,
114110
log_level=logging.DEBUG,
@@ -163,3 +159,4 @@ def logwrap(
163159
log_call_args_on_exc=log_call_args_on_exc,
164160
log_result_obj=log_result_obj
165161
)
162+
# pylint: enable=unexpected-keyword-arg

logwrap/_log_wrap_shared.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
def _check_type(expected):
4343
def deco(func):
4444
"""Check type before asign."""
45+
# pylint: disable=missing-docstring
4546
@functools.wraps(func)
4647
def wrapper(self, val):
4748
if not isinstance(val, expected):
@@ -52,6 +53,8 @@ def wrapper(self, val):
5253
)
5354
)
5455
return func(self, val)
56+
57+
# pylint: enable=missing-docstring
5558
return wrapper
5659
return deco
5760

@@ -63,10 +66,13 @@ def wraps(
6366
updated=functools.WRAPPER_UPDATES
6467
):
6568
"""Backport of functools.wraps to older python versions."""
69+
# pylint: disable=missing-docstring
6670
def wrapper(f):
6771
f = functools.wraps(wrapped, assigned, updated)(f)
6872
f.__wrapped__ = wrapped
6973
return f
74+
75+
# pylint: enable=missing-docstring
7076
return wrapper
7177
else:
7278
wraps = functools.wraps
@@ -154,6 +160,8 @@ def __init__(
154160

155161
self.__wrap_func_self()
156162

163+
super(BaseLogWrap, self).__init__()
164+
157165
def __wrap_func_self(self):
158166
"""Mark self as function wrapper. Usd only without arguments."""
159167
if self.__func is not None:
@@ -319,6 +327,17 @@ def _make_done_record(self, func_name, result):
319327
msg=msg
320328
)
321329

330+
def _make_calling_record(self, name, arguments, method='Calling'):
331+
"""Make log record before execution."""
332+
self._logger.log(
333+
level=self.log_level,
334+
msg="{method}: \n{name!r}({arguments})".format(
335+
method=method,
336+
name=name,
337+
arguments=arguments if self.log_call_args else ''
338+
)
339+
)
340+
322341
@abc.abstractmethod
323342
def _get_function_wrapper(self, func):
324343
"""Here should be constructed and returned real decorator.

0 commit comments

Comments
 (0)