Skip to content

Commit 6edc0b3

Browse files
committed
Improve traceback message
1 parent bcd687f commit 6edc0b3

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/instamatic/TEMController/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
warnings.warn(
99
'The `TEMController` module is deprecated since version 2.0.6. Use the `controller`-module instead',
1010
VisibleDeprecationWarning,
11+
stacklevel=2,
1112
)
1213

1314

src/instamatic/utils/deprecated.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22

33
from __future__ import annotations
44

5+
56
class VisibleDeprecationWarning(UserWarning):
6-
"""
7-
Numpy-inspired deprecation warning which will be shown by default.
7+
"""Numpy-inspired deprecation warning which will be shown by default.
8+
89
The default `DeprecationWarning` does not show by default.
910
"""
1011

12+
1113
def deprecated(since: str, alternative: str, removed: str = None):
1214
"""Mark a function as deprecated, printing a warning whenever it is used.
1315
@@ -34,7 +36,7 @@ def wrapped(*args, **kwargs):
3436
msg = f'Function {func.__name__} is deprecated since {since}, use {alternative} instead.'
3537
if removed is not None:
3638
msg += f' Will be removed in version {removed}.'
37-
warnings.warn(msg, VisibleDeprecationWarning)
39+
warnings.warn(msg, VisibleDeprecationWarning, stacklevel=2)
3840
return func(*args, **kwargs)
3941

4042
return wrapped

0 commit comments

Comments
 (0)