Skip to content

Commit 8be26bc

Browse files
Modernize code with Python 3.10+ idioms
- Replace .format() with f-string in _tracing.py - Use walrus operator for dict.get() pattern in _tracing.py - Convert string concatenation to parenthesized f-strings in _callers.py 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 813a93d commit 8be26bc

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/pluggy/_callers.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,12 @@ def _raise_wrapfail(
6666
def _warn_teardown_exception(
6767
hook_name: str, hook_impl: HookImpl, e: BaseException
6868
) -> None:
69-
msg = "A plugin raised an exception during an old-style hookwrapper teardown.\n"
70-
msg += f"Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n"
71-
msg += f"{type(e).__name__}: {e}\n"
72-
msg += "For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning" # noqa: E501
69+
msg = (
70+
f"A plugin raised an exception during an old-style hookwrapper teardown.\n"
71+
f"Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n"
72+
f"{type(e).__name__}: {e}\n"
73+
f"For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning" # noqa: E501
74+
)
7375
warnings.warn(PluggyTeardownRaisedWarning(msg), stacklevel=6)
7476

7577

src/pluggy/_tracing.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _format_message(self, tags: Sequence[str], args: Sequence[object]) -> str:
3232
content = " ".join(map(str, args))
3333
indent = " " * self.indent
3434

35-
lines = ["{}{} [{}]\n".format(indent, content, ":".join(tags))]
35+
lines = [f"{indent}{content} [{':'.join(tags)}]\n"]
3636

3737
for name, value in extra.items():
3838
lines.append(f"{indent} {name}: {value}\n")
@@ -42,11 +42,7 @@ def _format_message(self, tags: Sequence[str], args: Sequence[object]) -> str:
4242
def _processmessage(self, tags: tuple[str, ...], args: tuple[object, ...]) -> None:
4343
if self._writer is not None and args:
4444
self._writer(self._format_message(tags, args))
45-
try:
46-
processor = self._tags2proc[tags]
47-
except KeyError:
48-
pass
49-
else:
45+
if processor := self._tags2proc.get(tags):
5046
processor(tags, args)
5147

5248
def setwriter(self, writer: _Writer | None) -> None:

0 commit comments

Comments
 (0)