From d5eab6d26e6a9a8ed48d39c280c3d38e46eee038 Mon Sep 17 00:00:00 2001 From: Laurent LAPORTE Date: Sun, 23 Feb 2020 20:04:41 +0100 Subject: [PATCH] Fix #13: Warning displays the correct filename and line number when decorating a class if wrapt does not have the compiled c extension. --- CHANGELOG.rst | 5 ++++- deprecated/classic.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index a48153a..210b916 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -31,6 +31,9 @@ Fix For more information, see `The Warning 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 ------------- @@ -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 diff --git a/deprecated/classic.py b/deprecated/classic.py index 1dfd23e..bbdce5a 100644 --- a/deprecated/classic.py +++ b/deprecated/classic.py @@ -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'')) @@ -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*