Skip to content

Commit 091bf81

Browse files
committed
Make more human-friendly function call repr
1 parent be89994 commit 091bf81

File tree

5 files changed

+85
-85
lines changed

5 files changed

+85
-85
lines changed

logwrap/log_wrap.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ def _get_func_args_repr(
509509
else:
510510
annotation = f" # type: {getattr(param.annotation, '__name__', param.annotation)!s}"
511511

512-
param_str += f"\n{'':<{INDENT}}{param.name!r}={val},{annotation}"
512+
param_str += f"\n{'':<{INDENT}}{param.name}={val},{annotation}"
513513
if param_str:
514514
param_str += "\n"
515515
return param_str
@@ -533,7 +533,7 @@ def _make_calling_record(self, name: str, arguments: str, method: str = "Calling
533533
:type arguments: str
534534
:type method: str
535535
"""
536-
self._logger.log(level=self.log_level, msg=f"{method}: \n{name!r}({arguments if self.log_call_args else ''})")
536+
self._logger.log(level=self.log_level, msg=f"{method}: \n{name}({arguments if self.log_call_args else ''})")
537537

538538
def _make_exc_record(self, name: str, arguments: str) -> None:
539539
"""Make log record if exception raised.
@@ -554,7 +554,7 @@ def _make_exc_record(self, name: str, arguments: str) -> None:
554554
level=self.exc_level,
555555
msg=(
556556
f"Failed: \n"
557-
f"{name!r}({arguments if self.log_call_args_on_exc else ''})\n"
557+
f"{name}({arguments if self.log_call_args_on_exc else ''})\n"
558558
f"{tb_text if self.log_traceback else ''}"
559559
),
560560
exc_info=False,

logwrap/log_wrap.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ cdef class LogWrap(class_decorator.BaseDecorator):
325325
else:
326326
annotation = f" # type: {getattr(param.annotation, '__name__', param.annotation)!s}"
327327

328-
param_str += f"\n{'':<{INDENT}}{param.name!r}={val},{annotation}"
328+
param_str += f"\n{'':<{INDENT}}{param.name}={val},{annotation}"
329329
if param_str:
330330
param_str += "\n"
331331
return param_str

test/test_log_wrap.py

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def func():
6565

6666
self.assertEqual(
6767
f"DEBUG>Calling: \n"
68-
f"'func'()\n"
68+
f"func()\n"
6969
f"DEBUG>Done: 'func' with result:\n"
7070
f"{logwrap.pretty_repr(result)}\n",
7171
self.stream.getvalue(),
@@ -82,9 +82,9 @@ def func(tst):
8282
self.assertEqual(result, arg)
8383
self.assertEqual(
8484
f"DEBUG>Calling: \n"
85-
f"'func'(\n"
85+
f"func(\n"
8686
f" # POSITIONAL_OR_KEYWORD:\n"
87-
f" 'tst'={logwrap.pretty_repr(arg, indent=8, no_indent_start=True)},\n"
87+
f" tst={logwrap.pretty_repr(arg, indent=8, no_indent_start=True)},\n"
8888
f")\n"
8989
f"DEBUG>Done: 'func' with result:\n"
9090
f"{logwrap.pretty_repr(result)}\n",
@@ -103,9 +103,9 @@ def func(tst=arg):
103103

104104
self.assertEqual(
105105
f"DEBUG>Calling: \n"
106-
f"'func'(\n"
106+
f"func(\n"
107107
f" # POSITIONAL_OR_KEYWORD:\n"
108-
f" 'tst'={logwrap.pretty_repr(arg, indent=8, no_indent_start=True)},\n"
108+
f" tst={logwrap.pretty_repr(arg, indent=8, no_indent_start=True)},\n"
109109
f")\n"
110110
f"DEBUG>Done: 'func' with result:\n"
111111
f"{logwrap.pretty_repr(result)}\n",
@@ -125,10 +125,10 @@ def func(arg_1, arg_2):
125125

126126
self.assertEqual(
127127
f"DEBUG>Calling: \n"
128-
f"'func'(\n"
128+
f"func(\n"
129129
f" # POSITIONAL_OR_KEYWORD:\n"
130-
f" 'arg_1'={logwrap.pretty_repr(arg1, indent=8, no_indent_start=True)},\n"
131-
f" 'arg_2'={logwrap.pretty_repr(arg2, indent=8, no_indent_start=True)},\n"
130+
f" arg_1={logwrap.pretty_repr(arg1, indent=8, no_indent_start=True)},\n"
131+
f" arg_2={logwrap.pretty_repr(arg2, indent=8, no_indent_start=True)},\n"
132132
f")\n"
133133
f"DEBUG>Done: 'func' with result:\n"
134134
f"{logwrap.pretty_repr(result)}\n",
@@ -148,11 +148,11 @@ def func(*args, **kwargs):
148148

149149
self.assertEqual(
150150
f"DEBUG>Calling: \n"
151-
f"'func'(\n"
151+
f"func(\n"
152152
f" # VAR_POSITIONAL:\n"
153-
f" 'args'={logwrap.pretty_repr(tuple(targs), indent=8, no_indent_start=True)},\n"
153+
f" args={logwrap.pretty_repr(tuple(targs), indent=8, no_indent_start=True)},\n"
154154
f" # VAR_KEYWORD:\n"
155-
f" 'kwargs'={logwrap.pretty_repr(tkwargs, indent=8, no_indent_start=True)},\n"
155+
f" kwargs={logwrap.pretty_repr(tkwargs, indent=8, no_indent_start=True)},\n"
156156
f")\n"
157157
f"DEBUG>Done: 'func' with result:\n"
158158
f"{logwrap.pretty_repr(result)}\n",
@@ -173,13 +173,13 @@ def func(arg, *positional, **named):
173173
self.assertEqual(result, (arg, tuple(targs), tkwargs))
174174
self.assertEqual(
175175
f"DEBUG>Calling: \n"
176-
f"'func'(\n"
176+
f"func(\n"
177177
f" # POSITIONAL_OR_KEYWORD:\n"
178-
f" 'arg'={logwrap.pretty_repr(arg, indent=8, no_indent_start=True)},\n"
178+
f" arg={logwrap.pretty_repr(arg, indent=8, no_indent_start=True)},\n"
179179
f" # VAR_POSITIONAL:\n"
180-
f" 'positional'={logwrap.pretty_repr(tuple(targs), indent=8, no_indent_start=True)},\n"
180+
f" positional={logwrap.pretty_repr(tuple(targs), indent=8, no_indent_start=True)},\n"
181181
f" # VAR_KEYWORD:\n"
182-
f" 'named'={logwrap.pretty_repr(tkwargs, indent=8, no_indent_start=True)},\n"
182+
f" named={logwrap.pretty_repr(tkwargs, indent=8, no_indent_start=True)},\n"
183183
f")\n"
184184
f"DEBUG>Done: 'func' with result:\n"
185185
f"{logwrap.pretty_repr(result)}\n",
@@ -196,9 +196,9 @@ def func():
196196

197197
self.assertEqual(
198198
'DEBUG>Calling: \n'
199-
"'func'()\n"
199+
"func()\n"
200200
'ERROR>Failed: \n'
201-
"'func'()\n"
201+
"func()\n"
202202
'Traceback (most recent call last):',
203203
'\n'.join(self.stream.getvalue().split('\n')[:5]),
204204
)
@@ -223,11 +223,11 @@ def func():
223223
[
224224
mock.call(
225225
level=logging.INFO,
226-
msg="Calling: \n'func'()"
226+
msg="Calling: \nfunc()"
227227
),
228228
mock.call(
229229
level=logging.WARNING,
230-
msg=AnyStringWith("Failed: \n'func'()"),
230+
msg=AnyStringWith("Failed: \nfunc()"),
231231
exc_info=False
232232
),
233233
],
@@ -259,9 +259,9 @@ def func(*args, **kwargs):
259259
mock.call(
260260
level=logging.DEBUG,
261261
msg=f"Calling: \n"
262-
f"'func'(\n"
262+
f"func(\n"
263263
f" # POSITIONAL_OR_KEYWORD:\n"
264-
f" 'arg'={logwrap.pretty_repr(arg, indent=8, no_indent_start=True)},\n"
264+
f" arg={logwrap.pretty_repr(arg, indent=8, no_indent_start=True)},\n"
265265
f")"),
266266
mock.call(
267267
level=logging.DEBUG,
@@ -287,7 +287,7 @@ def func():
287287
mock.call(
288288
level=logging.DEBUG,
289289
msg="Calling: \n"
290-
"'func'()"),
290+
"func()"),
291291
mock.call(
292292
level=logging.DEBUG,
293293
msg=f"Done: 'func' with result:\n"
@@ -310,9 +310,9 @@ def __repr__(tst_self):
310310
self.assertEqual(result, 'No args')
311311
self.assertEqual(
312312
f"DEBUG>Calling: \n"
313-
f"'func'(\n"
313+
f"func(\n"
314314
f" # POSITIONAL_OR_KEYWORD:\n"
315-
f" 'tst_self'={logwrap.pretty_repr(tst)},\n"
315+
f" tst_self={logwrap.pretty_repr(tst)},\n"
316316
f")\n"
317317
f"DEBUG>Done: 'func' with result:\n"
318318
f"{logwrap.pretty_repr(result)}\n",
@@ -328,7 +328,7 @@ def func():
328328
self.assertEqual(result, 'No args')
329329
self.assertEqual(
330330
f"DEBUG>Calling: \n"
331-
f"'func'()\n"
331+
f"func()\n"
332332
f"DEBUG>Done: 'func' with result:\n"
333333
f"{logwrap.pretty_repr(result)}\n",
334334
self.stream.getvalue(),
@@ -353,17 +353,17 @@ def tst(arg, darg=1, *args, kwarg, dkwarg=4, **kwargs):
353353
mock.call(
354354
level=logging.DEBUG,
355355
msg=f"Calling: \n"
356-
f"'tst'(\n"
356+
f"tst(\n"
357357
f" # POSITIONAL_OR_KEYWORD:\n"
358-
f" 'arg'=0,\n"
359-
f" 'darg'=1,\n"
358+
f" arg=0,\n"
359+
f" darg=1,\n"
360360
f" # VAR_POSITIONAL:\n"
361-
f" 'args'={logwrap.pretty_repr((2,), indent=8, no_indent_start=True)},\n"
361+
f" args={logwrap.pretty_repr((2,), indent=8, no_indent_start=True)},\n"
362362
f" # KEYWORD_ONLY:\n"
363-
f" 'kwarg'=3,\n"
364-
f" 'dkwarg'=4,\n"
363+
f" kwarg=3,\n"
364+
f" dkwarg=4,\n"
365365
f" # VAR_KEYWORD:\n"
366-
f" 'kwargs'={logwrap.pretty_repr(dict(somekwarg=5), indent=8, no_indent_start=True)},\n"
366+
f" kwargs={logwrap.pretty_repr(dict(somekwarg=5), indent=8, no_indent_start=True)},\n"
367367
f")"),
368368
mock.call(
369369
level=logging.DEBUG,
@@ -392,14 +392,14 @@ def func(arg, darg=1, *args, **kwargs):
392392
)
393393
self.assertEqual(
394394
f"DEBUG>Calling: \n"
395-
f"'func'(\n"
395+
f"func(\n"
396396
f" # POSITIONAL_OR_KEYWORD:\n"
397-
f" 'arg'=0,\n"
398-
f" 'darg'=1,\n"
397+
f" arg=0,\n"
398+
f" darg=1,\n"
399399
f" # VAR_POSITIONAL:\n"
400-
f" 'args'={logwrap.pretty_repr((2, ), indent=8, no_indent_start=True)},\n"
400+
f" args={logwrap.pretty_repr((2, ), indent=8, no_indent_start=True)},\n"
401401
f" # VAR_KEYWORD:\n"
402-
f" 'kwargs'={logwrap.pretty_repr(dict(arg3=3), indent=8, no_indent_start=True)},\n"
402+
f" kwargs={logwrap.pretty_repr(dict(arg3=3), indent=8, no_indent_start=True)},\n"
403403
f")\n"
404404
f"DEBUG>Done: 'func' with result:\n"
405405
f"{logwrap.pretty_repr(result)}\n",
@@ -427,9 +427,9 @@ def func(test_arg1, test_arg2):
427427
level=logging.DEBUG,
428428
msg=(
429429
f"Calling: \n"
430-
f"'func'(\n"
430+
f"func(\n"
431431
f" # POSITIONAL_OR_KEYWORD:\n"
432-
f" 'test_arg1'={logwrap.pretty_repr(arg1, indent=8, no_indent_start=True)},\n"
432+
f" test_arg1={logwrap.pretty_repr(arg1, indent=8, no_indent_start=True)},\n"
433433
f")"
434434
)
435435
),
@@ -457,7 +457,7 @@ def func():
457457
[
458458
mock.call(
459459
level=logging.DEBUG,
460-
msg="Calling: \n'func'()"
460+
msg="Calling: \nfunc()"
461461
),
462462
],
463463
log.mock_calls,
@@ -482,7 +482,7 @@ def func(test_arg1, test_arg2):
482482
mock.call(
483483
level=logging.DEBUG,
484484
msg="Calling: \n"
485-
"'func'()"
485+
"func()"
486486
),
487487
mock.call(
488488
level=logging.DEBUG,
@@ -514,16 +514,16 @@ def func(test_arg1, test_arg2):
514514
level=logging.DEBUG,
515515
msg=(
516516
f"Calling: \n"
517-
f"'func'(\n"
517+
f"func(\n"
518518
f" # POSITIONAL_OR_KEYWORD:\n"
519-
f" 'test_arg1'={logwrap.pretty_repr(arg1, indent=8, no_indent_start=True)},\n"
520-
f" 'test_arg2'={logwrap.pretty_repr(arg2, indent=8, no_indent_start=True)},\n"
519+
f" test_arg1={logwrap.pretty_repr(arg1, indent=8, no_indent_start=True)},\n"
520+
f" test_arg2={logwrap.pretty_repr(arg2, indent=8, no_indent_start=True)},\n"
521521
f")"
522522
)
523523
),
524524
mock.call(
525525
level=logging.ERROR,
526-
msg=AnyStringWith("Failed: \n'func'()"),
526+
msg=AnyStringWith("Failed: \nfunc()"),
527527
exc_info=False
528528
),
529529
],
@@ -554,11 +554,11 @@ def func(test_arg1, test_arg2):
554554
mock.call(
555555
level=logging.DEBUG,
556556
msg="Calling: \n"
557-
"'func'()"
557+
"func()"
558558
),
559559
mock.call(
560560
level=logging.ERROR,
561-
msg=AnyStringWith("Failed: \n'func'()"),
561+
msg=AnyStringWith("Failed: \nfunc()"),
562562
exc_info=False
563563
),
564564
],
@@ -580,7 +580,7 @@ def func():
580580
[
581581
mock.call(
582582
level=logging.DEBUG,
583-
msg="Calling: \n'func'()"
583+
msg="Calling: \nfunc()"
584584
),
585585
mock.call(
586586
level=logging.DEBUG,
@@ -599,11 +599,11 @@ def func(*args, **kwargs):
599599
self.assertEqual(result, 'No args')
600600
self.assertEqual(
601601
f"DEBUG>Calling: \n"
602-
f"'func'(\n"
602+
f"func(\n"
603603
f" # VAR_POSITIONAL:\n"
604-
f" 'args'=(),\n"
604+
f" args=(),\n"
605605
f" # VAR_KEYWORD:\n"
606-
f" 'kwargs'={{}},\n"
606+
f" kwargs={{}},\n"
607607
f")\n"
608608
f"DEBUG>Done: 'func' with result:\n"
609609
f"{logwrap.pretty_repr(result)}\n",
@@ -630,11 +630,11 @@ def func():
630630
mock.call(
631631
level=logging.DEBUG,
632632
msg="Calling: \n"
633-
"'func'()"
633+
"func()"
634634
),
635635
mock.call(
636636
level=logging.ERROR,
637-
msg=AnyStringWith("Failed: \n'func'()"),
637+
msg=AnyStringWith("Failed: \nfunc()"),
638638
exc_info=False
639639
),
640640
],
@@ -643,7 +643,7 @@ def func():
643643
self.assertNotEqual(
644644
mock.call(
645645
level=logging.ERROR,
646-
msg=AnyStringWith("Failed: \n'func'()\nTraceback (most recent call last):"),
646+
msg=AnyStringWith("Failed: \nfunc()\nTraceback (most recent call last):"),
647647
exc_info=False
648648
),
649649
log.mock_calls[1],
@@ -731,10 +731,10 @@ def func(arg, arg_skip, arg2=None, skip_arg=None):
731731
mock.call.log(
732732
level=logging.DEBUG,
733733
msg="Calling: \n"
734-
"'func'(\n"
734+
"func(\n"
735735
" # POSITIONAL_OR_KEYWORD:\n"
736-
" 'arg'=1,\n"
737-
" 'arg2'=None,\n"
736+
" arg=1,\n"
737+
" arg2=None,\n"
738738
")"),
739739
mock.call.log(level=logging.DEBUG, msg="Done: 'func'")
740740
]
@@ -765,12 +765,12 @@ def func(arg, arg_secret, arg2='public', secret_arg=('key')):
765765
mock.call.log(
766766
level=logging.DEBUG,
767767
msg="Calling: \n"
768-
"'func'(\n"
768+
"func(\n"
769769
" # POSITIONAL_OR_KEYWORD:\n"
770-
" 'arg'='data',\n"
771-
" 'arg_secret'=None,\n"
772-
" 'arg2'='public',\n"
773-
" 'secret_arg'=None,\n"
770+
" arg='data',\n"
771+
" arg_secret=None,\n"
772+
" arg2='public',\n"
773+
" secret_arg=None,\n"
774774
")"),
775775
mock.call.log(level=logging.DEBUG, msg="Done: 'func'")
776776
]
@@ -802,12 +802,12 @@ def func(arg, arg_secret, arg2='public', secret_arg=('key')):
802802
mock.call.log(
803803
level=logging.DEBUG,
804804
msg="Calling: \n"
805-
"'func'(\n"
805+
"func(\n"
806806
" # POSITIONAL_OR_KEYWORD:\n"
807-
" 'arg'='data',\n"
808-
" 'arg_secret'=<*hidden*>,\n"
809-
" 'arg2'='public',\n"
810-
" 'secret_arg'=<*hidden*>,\n"
807+
" arg='data',\n"
808+
" arg_secret=<*hidden*>,\n"
809+
" arg2='public',\n"
810+
" secret_arg=<*hidden*>,\n"
811811
")"),
812812
mock.call.log(level=logging.DEBUG, msg="Done: 'func'")
813813
]

0 commit comments

Comments
 (0)