Skip to content

Commit 939bf68

Browse files
committed
Fix call repr: extra indent for arg repr was not needed
1 parent ff0fd45 commit 939bf68

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

logwrap/log_wrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def _safe_val_repr(self, value: typing.Any) -> str:
506506
try:
507507
return repr_utils.pretty_repr(
508508
src=value,
509-
indent=INDENT + 4,
509+
indent=INDENT,
510510
no_indent_start=True,
511511
max_indent=self.max_indent,
512512
)

logwrap/log_wrap.pyx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ from logwrap cimport repr_utils
3434
__all__ = ("LogWrap", "logwrap", "BoundParameter", "bind_args_kwargs")
3535

3636
LOGGER = logging.getLogger("logwrap") # type: logging.Logger
37-
cdef unsigned long INDENT = 4
38-
cdef str _CURRENT_FILE = os.path.abspath(__file__)
37+
38+
cdef:
39+
unsigned long INDENT = 4
40+
str _CURRENT_FILE = os.path.abspath(__file__)
3941

4042
_WrappedT = typing.TypeVar("_WrappedT", bound=typing.Callable[..., typing.Any])
4143

@@ -320,7 +322,7 @@ cdef class LogWrap:
320322
try:
321323
return repr_utils.pretty_repr(
322324
src=value,
323-
indent=INDENT + 4,
325+
indent=INDENT,
324326
no_indent_start=True,
325327
max_indent=self.max_indent,
326328
)

test/test_log_wrap.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def func(tst):
8484
f"DEBUG>Calling: \n"
8585
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=4, no_indent_start=True)},\n"
8888
f")\n"
8989
f"DEBUG>Done: 'func' with result:\n"
9090
f"{logwrap.pretty_repr(result)}\n",
@@ -105,7 +105,7 @@ def func(tst=arg):
105105
f"DEBUG>Calling: \n"
106106
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=4, no_indent_start=True)},\n"
109109
f")\n"
110110
f"DEBUG>Done: 'func' with result:\n"
111111
f"{logwrap.pretty_repr(result)}\n",
@@ -127,8 +127,8 @@ def func(arg_1, arg_2):
127127
f"DEBUG>Calling: \n"
128128
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=4, no_indent_start=True)},\n"
131+
f" arg_2={logwrap.pretty_repr(arg2, indent=4, no_indent_start=True)},\n"
132132
f")\n"
133133
f"DEBUG>Done: 'func' with result:\n"
134134
f"{logwrap.pretty_repr(result)}\n",
@@ -150,9 +150,9 @@ def func(*args, **kwargs):
150150
f"DEBUG>Calling: \n"
151151
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=4, 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=4, no_indent_start=True)},\n"
156156
f")\n"
157157
f"DEBUG>Done: 'func' with result:\n"
158158
f"{logwrap.pretty_repr(result)}\n",
@@ -175,11 +175,11 @@ def func(arg, *positional, **named):
175175
f"DEBUG>Calling: \n"
176176
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=4, 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=4, 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=4, no_indent_start=True)},\n"
183183
f")\n"
184184
f"DEBUG>Done: 'func' with result:\n"
185185
f"{logwrap.pretty_repr(result)}\n",
@@ -195,7 +195,7 @@ def func():
195195
func()
196196

197197
self.assertEqual(
198-
"DEBUG>Calling: \n" "func()\n" "ERROR>Failed: \n" "func()\n" "Traceback (most recent call last):",
198+
"DEBUG>Calling: \nfunc()\nERROR>Failed: \nfunc()\nTraceback (most recent call last):",
199199
"\n".join(self.stream.getvalue().split("\n")[:5]),
200200
)
201201

@@ -232,7 +232,7 @@ def func():
232232

233233
self.assertEqual(
234234
[
235-
mock.call(level=logging.DEBUG, msg="Calling: \n" "func()"),
235+
mock.call(level=logging.DEBUG, msg="Calling: \nfunc()"),
236236
mock.call(
237237
level=logging.DEBUG,
238238
msg=f"Done: 'func' with result:\n" f"{logwrap.pretty_repr(result, max_indent=10)}",
@@ -289,15 +289,15 @@ def tst(arg, darg=1, *args, kwarg, dkwarg=4, **kwargs):
289289
f" arg=0,\n"
290290
f" darg=1,\n"
291291
f" # VAR_POSITIONAL:\n"
292-
f" args={logwrap.pretty_repr((2,), indent=8, no_indent_start=True)},\n"
292+
f" args={logwrap.pretty_repr((2,), indent=4, no_indent_start=True)},\n"
293293
f" # KEYWORD_ONLY:\n"
294294
f" kwarg=3,\n"
295295
f" dkwarg=4,\n"
296296
f" # VAR_KEYWORD:\n"
297-
f" kwargs={logwrap.pretty_repr(dict(somekwarg=5), indent=8, no_indent_start=True)},\n"
297+
f" kwargs={logwrap.pretty_repr(dict(somekwarg=5), indent=4, no_indent_start=True)},\n"
298298
f")",
299299
),
300-
mock.call(level=logging.DEBUG, msg="Done: 'tst' with result:\n" "None"),
300+
mock.call(level=logging.DEBUG, msg="Done: 'tst' with result:\nNone"),
301301
],
302302
)
303303

@@ -324,9 +324,9 @@ def func(arg, darg=1, *args, **kwargs):
324324
f" arg=0,\n"
325325
f" darg=1,\n"
326326
f" # VAR_POSITIONAL:\n"
327-
f" args={logwrap.pretty_repr((2, ), indent=8, no_indent_start=True)},\n"
327+
f" args={logwrap.pretty_repr((2, ), indent=4, no_indent_start=True)},\n"
328328
f" # VAR_KEYWORD:\n"
329-
f" kwargs={logwrap.pretty_repr(dict(arg3=3), indent=8, no_indent_start=True)},\n"
329+
f" kwargs={logwrap.pretty_repr(dict(arg3=3), indent=4, no_indent_start=True)},\n"
330330
f")\n"
331331
f"DEBUG>Done: 'func' with result:\n"
332332
f"{logwrap.pretty_repr(result)}\n",
@@ -356,7 +356,7 @@ def func(test_arg1, test_arg2):
356356
f"Calling: \n"
357357
f"func(\n"
358358
f" # POSITIONAL_OR_KEYWORD:\n"
359-
f" test_arg1={logwrap.pretty_repr(arg1, indent=8, no_indent_start=True)},\n"
359+
f" test_arg1={logwrap.pretty_repr(arg1, indent=4, no_indent_start=True)},\n"
360360
f")"
361361
),
362362
),
@@ -400,7 +400,7 @@ def func(test_arg1, test_arg2):
400400
self.assertEqual(result, (arg1, arg2))
401401
self.assertEqual(
402402
[
403-
mock.call(level=logging.DEBUG, msg="Calling: \n" "func()"),
403+
mock.call(level=logging.DEBUG, msg="Calling: \nfunc()"),
404404
mock.call(level=logging.DEBUG, msg=f"Done: 'func' with result:\n{logwrap.pretty_repr(result)}"),
405405
],
406406
log.mock_calls,
@@ -429,8 +429,8 @@ def func(test_arg1, test_arg2):
429429
f"Calling: \n"
430430
f"func(\n"
431431
f" # POSITIONAL_OR_KEYWORD:\n"
432-
f" test_arg1={logwrap.pretty_repr(arg1, indent=8, no_indent_start=True)},\n"
433-
f" test_arg2={logwrap.pretty_repr(arg2, indent=8, no_indent_start=True)},\n"
432+
f" test_arg1={logwrap.pretty_repr(arg1, indent=4, no_indent_start=True)},\n"
433+
f" test_arg2={logwrap.pretty_repr(arg2, indent=4, no_indent_start=True)},\n"
434434
f")"
435435
),
436436
),
@@ -456,7 +456,7 @@ def func(test_arg1, test_arg2):
456456

457457
self.assertEqual(
458458
[
459-
mock.call(level=logging.DEBUG, msg="Calling: \n" "func()"),
459+
mock.call(level=logging.DEBUG, msg="Calling: \nfunc()"),
460460
mock.call(level=logging.ERROR, msg=AnyStringWith("Failed: \nfunc()"), exc_info=False),
461461
],
462462
log.mock_calls,
@@ -515,7 +515,7 @@ def func():
515515

516516
self.assertEqual(
517517
[
518-
mock.call(level=logging.DEBUG, msg="Calling: \n" "func()"),
518+
mock.call(level=logging.DEBUG, msg="Calling: \nfunc()"),
519519
mock.call(level=logging.ERROR, msg=AnyStringWith("Failed: \nfunc()"), exc_info=False),
520520
],
521521
log.mock_calls,
@@ -631,7 +631,7 @@ def func(arg, arg_skip, arg2=None, skip_arg=None):
631631
[
632632
mock.call.log(
633633
level=logging.DEBUG,
634-
msg="Calling: \n" "func(\n" " # POSITIONAL_OR_KEYWORD:\n" " arg=1,\n" " arg2=None,\n" ")",
634+
msg="Calling: \nfunc(\n # POSITIONAL_OR_KEYWORD:\n arg=1,\n arg2=None,\n)",
635635
),
636636
mock.call.log(level=logging.DEBUG, msg="Done: 'func'"),
637637
],

0 commit comments

Comments
 (0)