Skip to content

Commit

Permalink
Fix #13: Warning displays the correct filename and line number when d…
Browse files Browse the repository at this point in the history
…ecorating a class if wrapt does not have the compiled c extension.
  • Loading branch information
tantale committed Feb 23, 2020
1 parent 794bbf9 commit d5eab6d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -31,6 +31,9 @@ Fix
For more information, see `The Warning Filter <https://docs.python.org/3/library/warnings.html#the-warnings-filter>`_
in the Python documentation.

- Fix #13: Warning displays the correct filename and line number when decorating a class if wrapt
does not have the compiled c extension.

Documentation
-------------

Expand All @@ -55,7 +58,7 @@ Bug fix release
Fix
---

- Warning displays the correct filename and line number when decorating a function if wrapt
- Fix #13: Warning displays the correct filename and line number when decorating a function if wrapt
does not have the compiled c extension.

Other
Expand Down
4 changes: 2 additions & 2 deletions deprecated/classic.py
Expand Up @@ -18,11 +18,11 @@
# stack level that should be passed to warnings.warn should be 2. However, if using
# a pure python wrapt, a extra stacklevel is required.
import wrapt._wrappers

_stacklevel = 2
except ImportError:
_stacklevel = 3


string_types = (type(b''), type(u''))


Expand Down Expand Up @@ -158,7 +158,7 @@ def wrapped_cls(cls, *args, **kwargs):
with warnings.catch_warnings():
if self.action:
warnings.simplefilter(self.action, self.category)
warnings.warn(msg, category=self.category, stacklevel=2)
warnings.warn(msg, category=self.category, stacklevel=_stacklevel)
if old_new1 is object.__new__:
return old_new1(cls)
# actually, we don't know the real signature of *old_new1*
Expand Down

0 comments on commit d5eab6d

Please sign in to comment.