Skip to content

Commit 9e10722

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent e7f6b98 commit 9e10722

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

src/pluggy/_tracing.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"""
44
from __future__ import annotations
55

6+
import reprlib
67
from typing import Any
78
from typing import Callable
89
from typing import Sequence
910
from typing import Tuple
10-
import reprlib
1111

1212

1313
_Writer = Callable[[str], object]
@@ -60,6 +60,7 @@ def setprocessor(self, tags: str | tuple[str, ...], processor: _Processor) -> No
6060
assert isinstance(tags, tuple)
6161
self._tags2proc[tags] = processor
6262

63+
6364
def _try_repr_or_str(obj: object) -> str:
6465
try:
6566
return repr(obj)
@@ -68,6 +69,7 @@ def _try_repr_or_str(obj: object) -> str:
6869
except BaseException:
6970
return f'{type(obj).__name__}("{obj}")'
7071

72+
7173
def _format_repr_exception(exc: BaseException, obj: object) -> str:
7274
try:
7375
exc_info = _try_repr_or_str(exc)
@@ -79,13 +81,15 @@ def _format_repr_exception(exc: BaseException, obj: object) -> str:
7981
exc_info, type(obj).__name__, id(obj)
8082
)
8183

84+
8285
def _ellipsize(s: str, maxsize: int) -> str:
8386
if len(s) > maxsize:
8487
i = max(0, (maxsize - 3) // 2)
8588
j = max(0, maxsize - 3 - i)
8689
return s[:i] + "..." + s[len(s) - j :]
8790
return s
8891

92+
8993
class SafeRepr(reprlib.Repr):
9094
"""
9195
repr.Repr that limits the resulting size of repr() and includes
@@ -136,6 +140,8 @@ def repr_instance(self, x: object, level: int) -> str:
136140

137141
# Maximum size of overall repr of objects to display during assertion errors.
138142
DEFAULT_REPR_MAX_SIZE = 240
143+
144+
139145
def saferepr(
140146
obj: object, maxsize: Optional[int] = DEFAULT_REPR_MAX_SIZE, use_ascii: bool = False
141147
) -> str:
@@ -151,6 +157,7 @@ def saferepr(
151157

152158
return SafeRepr(maxsize, use_ascii).repr(obj)
153159

160+
154161
class TagTracerSub:
155162
def __init__(self, root: TagTracer, tags: tuple[str, ...]) -> None:
156163
self.root = root

testing/benchmark.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
"""
44
import pytest
55

6+
from ._tracing import saferepr
67
from pluggy import HookimplMarker
78
from pluggy import HookspecMarker
89
from pluggy import PluginManager
910
from pluggy._callers import _multicall
1011
from pluggy._hooks import HookImpl
1112

12-
from ._tracing import saferepr
13-
1413

1514
hookspec = HookspecMarker("example")
1615
hookimpl = HookimplMarker("example")

testing/test_hookcaller.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,10 @@ def conflict(self) -> None:
450450
"<class 'test_hookcaller.test_hook_conflict.<locals>.Api1'>"
451451
)
452452

453-
def test_hookcaller_repr_with_saferepr_failure(hc: HookCaller, addmeth: AddMeth) -> None:
453+
454+
def test_hookcaller_repr_with_saferepr_failure(
455+
hc: HookCaller, addmeth: AddMeth
456+
) -> None:
454457
@addmeth()
455458
def he_method1() -> None:
456459
pass
@@ -466,4 +469,4 @@ def he_method3() -> None:
466469

467470
# Verify that HookCaller.repr with saferepr still works despite the error
468471
expected_repr = f"<HookCaller {saferepr(hc.name)}>"
469-
assert repr(hc) == expected_repr
472+
assert repr(hc) == expected_repr

testing/test_tracer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import pytest
44

5-
from pluggy._tracing import saferepr, DEFAULT_REPR_MAX_SIZE
5+
from pluggy._tracing import DEFAULT_REPR_MAX_SIZE
6+
from pluggy._tracing import saferepr
67
from pluggy._tracing import TagTracer
78

89

@@ -79,6 +80,7 @@ def test_setprocessor(rootlogger: TagTracer) -> None:
7980
tags, args = l2[0]
8081
assert args == ("seen",)
8182

83+
8284
def test_saferepr_simple_repr():
8385
assert saferepr(1) == "1"
8486
assert saferepr(None) == "None"
@@ -247,4 +249,4 @@ def __repr__(self):
247249

248250
assert saferepr(SomeClass()).startswith(
249251
"<[RuntimeError() raised in repr()] SomeClass object at 0x"
250-
)
252+
)

0 commit comments

Comments
 (0)