Skip to content

Commit cff191d

Browse files
Anusha ShekharAnusha Shekhar
authored andcommitted
Update all repr occurences to use saferepr
1 parent 3499ef5 commit cff191d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/pluggy/_hooks.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from typing import Union
2626

2727
from ._result import Result
28+
from ._tracing import saferepr
2829

2930

3031
_T = TypeVar("_T")
@@ -456,7 +457,7 @@ def _add_hookimpl(self, hookimpl: HookImpl) -> None:
456457
self._hookimpls.insert(i + 1, hookimpl)
457458

458459
def __repr__(self) -> str:
459-
return f"<HookCaller {self.name!r}>"
460+
return f"<HookCaller {saferepr(self.name)}>"
460461

461462
def _verify_all_args_are_provided(self, kwargs: Mapping[str, object]) -> None:
462463
# This is written to avoid expensive operations when not needed.
@@ -609,7 +610,7 @@ def _call_history(self) -> _CallHistory | None: # type: ignore[override]
609610
return self._orig._call_history
610611

611612
def __repr__(self) -> str:
612-
return f"<_SubsetHookCaller {self.name!r}>"
613+
return f"<_SubsetHookCaller {saferepr(self.name)}>"
613614

614615

615616
@final
@@ -667,7 +668,7 @@ def __init__(
667668
self.trylast: Final = hook_impl_opts["trylast"]
668669

669670
def __repr__(self) -> str:
670-
return f"<HookImpl plugin_name={self.plugin_name!r}, plugin={self.plugin!r}>"
671+
return f"<HookImpl plugin_name={saferepr(self.plugin_name)}, plugin={saferepr(self.plugin)}>"
671672

672673

673674
@final

testing/benchmark.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from pluggy._callers import _multicall
1010
from pluggy._hooks import HookImpl
1111

12+
from ._tracing import saferepr
13+
1214

1315
hookspec = HookspecMarker("example")
1416
hookimpl = HookimplMarker("example")
@@ -77,7 +79,7 @@ def __init__(self, num: int) -> None:
7779
self.num = num
7880

7981
def __repr__(self) -> str:
80-
return f"<Plugin {self.num}>"
82+
return f"<Plugin {saferepr(self.num)}>"
8183

8284
@hookimpl
8385
def fun(self, hooks, nesting: int) -> None:
@@ -89,7 +91,7 @@ def __init__(self, num: int) -> None:
8991
self.num = num
9092

9193
def __repr__(self) -> str:
92-
return f"<PluginWrap {self.num}>"
94+
return f"<PluginWrap {saferepr(self.num)}>"
9395

9496
@hookimpl(wrapper=True)
9597
def fun(self):

0 commit comments

Comments
 (0)