Skip to content

Commit 854390f

Browse files
authored
Merge pull request #69 from pyiron/deprecate_f
Fix `deprecate` f-string usage
2 parents 541f58c + 37525a2 commit 854390f

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

pyiron_snippets/deprecate.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ def decorated(*args, **kwargs):
146146
if kw in self.arguments:
147147
warnings.warn(
148148
message_format.format(
149-
"{function.__module__}.{function.__name__}({kw}={kwargs[kw]})"
149+
f"{function.__module__}.{function.__qualname__}"
150+
f"({kw}={kwargs[kw]})"
150151
),
151152
category=self.category,
152153
stacklevel=2,

tests/unit/test_deprecate.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
from pyiron_snippets.deprecate import deprecate, deprecate_soon
55

66

7+
class ToGiveAQualname:
8+
content = "this is the string"
9+
10+
@staticmethod
11+
@deprecate(bar=f"Instead of {content}, we want to see a string")
12+
def foo(bar=None, baz=None):
13+
pass
14+
15+
716
class TestDeprecator(unittest.TestCase):
817
def test_deprecate(self):
918
"""Function decorated with `deprecate` should raise a warning."""
@@ -125,6 +134,15 @@ def food(bar=None, baz=None):
125134
food(baz=True)
126135
self.assertEqual(len(w), 2, "Not all warnings preserved.")
127136

137+
def test_warning_reference(self):
138+
with warnings.catch_warnings(record=True) as w:
139+
ToGiveAQualname.foo(bar=True)
140+
self.assertIn(
141+
f"{ToGiveAQualname.foo.__module__}.{ToGiveAQualname.foo.__qualname__}",
142+
str(w[0].message),
143+
msg="Ensure full reference to function appears in warning.",
144+
)
145+
128146

129147
if __name__ == "__main__":
130148
unittest.main()

0 commit comments

Comments
 (0)