Skip to content

Commit 59b0d58

Browse files
committed
extra docstrings
1 parent a5d034a commit 59b0d58

File tree

5 files changed

+55
-10
lines changed

5 files changed

+55
-10
lines changed

logwrap/class_decorator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def __init__(self, func: typing.Optional[typing.Callable[..., ReturnType]] = Non
7171
:param func: function to wrap
7272
:type func: typing.Optional[typing.Callable]
7373
"""
74-
# noinspection PyArgumentList
7574
super().__init__()
7675
self.__func: typing.Optional[typing.Callable[..., ReturnType]] = func
7776
if self.__func is not None:
@@ -81,6 +80,7 @@ def __init__(self, func: typing.Optional[typing.Callable[..., ReturnType]] = Non
8180
def _func(self) -> typing.Optional[typing.Callable[..., ReturnType]]:
8281
"""Get wrapped function.
8382
83+
:return: wrapped function
8484
:rtype: typing.Optional[typing.Callable]
8585
"""
8686
return self.__func # pragma: no cover
@@ -91,6 +91,7 @@ def _get_function_wrapper(self, func: typing.Callable[..., ReturnType]) -> typin
9191
9292
:param func: Wrapped function
9393
:type func: typing.Callable
94+
:return: function wrapper
9495
:rtype: typing.Callable
9596
"""
9697
raise NotImplementedError()
@@ -131,7 +132,7 @@ def __repr__(self) -> str:
131132
:return: representation for logging/debug purposes
132133
:rtype: str
133134
"""
134-
return f"<{self.__class__.__name__}({self.__func!r}) at 0x{id(self):X}>" # pragma: no cover
135+
return f"<{self.__class__.__name__}({self.__func!r}) at 0x{id(self):X}>"
135136

136137

137138
# 8<----------------------------------------------------------------------------

logwrap/class_decorator.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ cdef class BaseDecorator:
3434
:param func: function to wrap
3535
:type func: typing.Optional[typing.Callable]
3636
"""
37-
# noinspection PyArgumentList
3837
super().__init__()
3938
self._func = func
4039
if self._func is not None:
@@ -45,6 +44,7 @@ cdef class BaseDecorator:
4544

4645
:param func: Wrapped function
4746
:type func: typing.Callable
47+
:return: function wrapper
4848
:rtype: typing.Callable
4949
"""
5050
raise NotImplementedError()
@@ -73,4 +73,4 @@ cdef class BaseDecorator:
7373
:return: representation for logging/debug purposes
7474
:rtype: str
7575
"""
76-
return f"<{self.__class__.__name__}({self._func!r}) at 0x{id(self):X}>" # pragma: no cover
76+
return f"<{self.__class__.__name__}({self._func!r}) at 0x{id(self):X}>"

logwrap/log_wrap.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ def __str__(self) -> str:
8585
:return: string representation for parameter. */** flags is attached if positional (*args) or keyword (**kwargs)
8686
:rtype: str
8787
"""
88-
# POSITIONAL_ONLY is only in precompiled functions
88+
# POSITIONAL_ONLY is only in precompiled functions or Python 3.8+
8989
if self.kind == self.POSITIONAL_ONLY: # pragma: no cover
9090
as_str: str = "" if self.name is None else f"<{self.name}>"
9191
else:
9292
as_str = self.name or ""
9393

9494
# Add annotation if applicable (python 3 only)
95-
if self.annotation is not self.empty: # pragma: no cover
95+
if self.annotation is not self.empty:
9696
as_str += f": {inspect.formatannotation(self.annotation)!s}"
9797

9898
value = self.value
@@ -145,7 +145,6 @@ def bind_args_kwargs(sig: inspect.Signature, *args: typing.Any, **kwargs: typing
145145
return result
146146

147147

148-
# noinspection PyAbstractClass
149148
class LogWrap(class_decorator.BaseDecorator):
150149
"""Base class for LogWrap implementation."""
151150

@@ -270,6 +269,7 @@ def _get_logger_for_func(self, func: FuncResultType) -> logging.Logger:
270269
def log_level(self) -> int:
271270
"""Log level for normal behavior.
272271
272+
:return: log level for normal behavior
273273
:rtype: int
274274
"""
275275
return self.__log_level
@@ -290,6 +290,7 @@ def log_level(self, val: int) -> None:
290290
def exc_level(self) -> int:
291291
"""Log level for exceptions.
292292
293+
:return: log level for exceptions cases
293294
:rtype: int
294295
"""
295296
return self.__exc_level
@@ -310,6 +311,7 @@ def exc_level(self, val: int) -> None:
310311
def max_indent(self) -> int:
311312
"""Maximum indentation.
312313
314+
:return: maximum allowed identation before switch to normal repr
313315
:rtype: int
314316
"""
315317
return self.__max_indent
@@ -330,6 +332,7 @@ def max_indent(self, val: int) -> None:
330332
def blacklisted_names(self) -> typing.List[str]:
331333
"""List of arguments names to ignore in log.
332334
335+
:return: list of arguments to ignore in log
333336
:rtype: typing.List[str]
334337
"""
335338
return self.__blacklisted_names
@@ -338,6 +341,7 @@ def blacklisted_names(self) -> typing.List[str]:
338341
def blacklisted_exceptions(self) -> typing.List[typing.Type[Exception]]:
339342
"""List of exceptions to re-raise without log traceback and text.
340343
344+
:return: list of exceptions to re-raise silent
341345
:rtype: typing.List[typing.Type[Exception]]
342346
"""
343347
return self.__blacklisted_exceptions
@@ -346,6 +350,7 @@ def blacklisted_exceptions(self) -> typing.List[typing.Type[Exception]]:
346350
def log_call_args(self) -> bool:
347351
"""Flag: log call arguments before call.
348352
353+
:return: log cal arguments before call
349354
:rtype: bool
350355
"""
351356
return self.__log_call_args
@@ -366,6 +371,7 @@ def log_call_args(self, val: bool) -> None:
366371
def log_call_args_on_exc(self) -> bool:
367372
"""Flag: log call arguments on exception.
368373
374+
:return: log call arguments in case of exception logging
369375
:rtype: bool
370376
"""
371377
return self.__log_call_args_on_exc
@@ -386,6 +392,7 @@ def log_call_args_on_exc(self, val: bool) -> None:
386392
def log_traceback(self) -> bool:
387393
"""Flag: log traceback on exception.
388394
395+
:return: log traceback in case of exception logging
389396
:rtype: bool
390397
"""
391398
return self.__log_traceback
@@ -406,6 +413,7 @@ def log_traceback(self, val: bool) -> None:
406413
def log_result_obj(self) -> bool:
407414
"""Flag: log result object.
408415
416+
:return: log execution result object
409417
:rtype: bool
410418
"""
411419
return self.__log_result_obj
@@ -426,6 +434,7 @@ def log_result_obj(self, val: bool) -> None:
426434
def _logger(self) -> typing.Optional[logging.Logger]:
427435
"""Logger instance.
428436
437+
:return: logger instance if configured
429438
:rtype: typing.Optional[logging.Logger]
430439
"""
431440
return self.__logger
@@ -434,6 +443,7 @@ def _logger(self) -> typing.Optional[logging.Logger]:
434443
def _spec(self) -> typing.Optional[typing.Callable[..., FuncResultType]]:
435444
"""Spec for function arguments.
436445
446+
:return: function specification to grab information from
437447
:rtype: typing.Callable
438448
"""
439449
return self.__spec
@@ -560,8 +570,11 @@ def _get_func_args_repr(
560570
def _make_done_record(self, logger: logging.Logger, func_name: str, result: typing.Any) -> None:
561571
"""Construct success record.
562572
573+
:param logger: logger instance to use
563574
:type logger: logging.Logger
575+
:param func_name: function name
564576
:type func_name: str
577+
:param result: function execution result
565578
:type result: typing.Any
566579
"""
567580
msg: str = f"Done: {func_name!r}"
@@ -573,19 +586,27 @@ def _make_done_record(self, logger: logging.Logger, func_name: str, result: typi
573586
def _make_calling_record(self, logger: logging.Logger, name: str, arguments: str, method: str = "Calling") -> None:
574587
"""Make log record before execution.
575588
589+
:param logger: logger instance to use
576590
:type logger: logging.Logger
591+
:param name: function name
577592
:type name: str
593+
:param arguments: function arguments repr
578594
:type arguments: str
595+
:param method: "calling" or "awaiting"
579596
:type method: str
580597
"""
581598
logger.log(level=self.log_level, msg=f"{method}: \n{name}({arguments if self.log_call_args else ''})")
582599

583600
def _make_exc_record(self, logger: logging.Logger, name: str, arguments: str, exception: Exception) -> None:
584601
"""Make log record if exception raised.
585602
603+
:param logger: logger instance to use
586604
:type logger: logging.Logger
605+
:param name: function name
587606
:type name: str
607+
:param arguments: function arguments repr
588608
:type arguments: str
609+
:param exception: exception captured
589610
:type exception: Exception
590611
"""
591612
exc_info = sys.exc_info()

logwrap/log_wrap.pyx

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,20 @@ cdef class LogWrap(class_decorator.BaseDecorator):
251251

252252
@property
253253
def blacklisted_names(self) -> typing.List[str]:
254-
"""List of arguments names to ignore in log."""
254+
"""List of arguments names to ignore in log.
255+
256+
:return: list of arguments to ignore in log
257+
:rtype: typing.List[str]
258+
"""
255259
return self.__blacklisted_names
256260

257261
@property
258262
def blacklisted_exceptions(self) -> typing.List[typing.Type[Exception]]:
259-
"""List of exceptions to re-raise without log."""
263+
"""List of exceptions to re-raise without log.
264+
265+
:return: list of exceptions to re-raise silent
266+
:rtype: typing.List[typing.Type[Exception]]
267+
"""
260268
return self.__blacklisted_exceptions
261269

262270
def __repr__(self) -> str:
@@ -373,8 +381,11 @@ cdef class LogWrap(class_decorator.BaseDecorator):
373381
void _make_done_record(self, logger: logging.Logger, str func_name, result: typing.Any) except *:
374382
"""Construct success record.
375383
384+
:param logger: logger instance to use
376385
:type logger: logging.Logger
386+
:param func_name: function name
377387
:type func_name: str
388+
:param result: function execution result
378389
:type result: typing.Any
379390
"""
380391
cdef:
@@ -396,9 +407,13 @@ cdef class LogWrap(class_decorator.BaseDecorator):
396407
void _make_calling_record(self, logger: logging.Logger, str name, str arguments, str method="Calling") except *:
397408
"""Make log record before execution.
398409
410+
:param logger: logger instance to use
399411
:type logger: logging.Logger
412+
:param name: function name
400413
:type name: str
414+
:param arguments: function arguments repr
401415
:type arguments: str
416+
:param method: "calling" or "awaiting"
402417
:type method: str
403418
"""
404419
logger.log(
@@ -409,9 +424,13 @@ cdef class LogWrap(class_decorator.BaseDecorator):
409424
void _make_exc_record(self, logger: logging.Logger, str name, str arguments, Exception exception) except *:
410425
"""Make log record if exception raised.
411426
427+
:param logger: logger instance to use
412428
:type logger: logging.Logger
429+
:param name: function name
413430
:type name: str
431+
:param arguments: function arguments repr
414432
:type arguments: str
433+
:param exception: exception captured
415434
:type exception: Exception
416435
"""
417436
exc_info = sys.exc_info()

logwrap/repr_utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def kind(self) -> int:
126126
return self.parameter.kind # type: ignore
127127

128128
# noinspection PyTypeChecker
129-
def __hash__(self) -> typing.NoReturn: # pragma: no cover
129+
def __hash__(self) -> typing.NoReturn:
130130
"""Block hashing.
131131
132132
:raises TypeError: Not hashable.
@@ -192,6 +192,7 @@ def __init__(self, max_indent: int = 20, indent_step: int = 4) -> None:
192192
def max_indent(self) -> int:
193193
"""Max indent getter.
194194
195+
:return: maximal indent before switch to normal repr
195196
:rtype: int
196197
"""
197198
return self.__max_indent
@@ -200,6 +201,7 @@ def max_indent(self) -> int:
200201
def indent_step(self) -> int:
201202
"""Indent step getter.
202203
204+
:return: indent step for nested definitions
203205
:rtype: int
204206
"""
205207
return self.__indent_step
@@ -323,6 +325,7 @@ def _repr_iterable_items(self, src: typing.Iterable[typing.Any], indent: int = 0
323325
def _magic_method_name(self) -> str:
324326
"""Magic method name.
325327
328+
:return: magic method name to lookup in processing objects
326329
:rtype: str
327330
"""
328331

@@ -398,6 +401,7 @@ class PrettyRepr(PrettyFormat):
398401
def _magic_method_name(self) -> str:
399402
"""Magic method name.
400403
404+
:return: magic method name to lookup in processing objects
401405
:rtype: str
402406
"""
403407
return "__pretty_repr__"

0 commit comments

Comments
 (0)