diff options
author | Seth M Morton <seth.m.morton@gmail.com> | 2018-11-17 17:41:15 -0800 |
---|---|---|
committer | Seth M Morton <seth.m.morton@gmail.com> | 2018-11-17 17:55:56 -0800 |
commit | 86f4b077210956e9cc00c74ddcf71aff999fe7c9 (patch) | |
tree | b14361fa1eb5e51bd6fb748df88739352c7deb06 | |
parent | 1e9a79613136c91e7d60c6b7274ad5fc317ea757 (diff) | |
download | natsort-86f4b077210956e9cc00c74ddcf71aff999fe7c9.tar.gz |
Add "stacklevel" to warnings.warn calls
This shows the user where the function that issues the warning was
called, rather than showing them where warnings.war was called.
-rw-r--r-- | natsort/natsort.py | 4 | ||||
-rw-r--r-- | natsort/utils.py | 7 |
2 files changed, 6 insertions, 5 deletions
diff --git a/natsort/natsort.py b/natsort/natsort.py index 5679c36..47cc9f1 100644 --- a/natsort/natsort.py +++ b/natsort/natsort.py @@ -284,7 +284,7 @@ def versorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): """ msg = "versorted is deprecated as of 5.5.0 and will be removed in 6.0.0, " msg += "please use natsorted instead." - warn(msg, DeprecationWarning) + warn(msg, DeprecationWarning, stacklevel=2) return natsorted(seq, key, reverse, alg, **_kwargs) @@ -480,7 +480,7 @@ def index_versorted(seq, key=None, reverse=False, alg=ns.DEFAULT, **_kwargs): """ msg = "index_versorted is deprecated as of 5.5.0 and will be removed in 6.0.0, " msg += "please use index_natsorted instead." - warn(msg, DeprecationWarning) + warn(msg, DeprecationWarning, stacklevel=2) return index_natsorted(seq, key, reverse, alg, **_kwargs) diff --git a/natsort/utils.py b/natsort/utils.py index 8a56cfd..8eafd76 100644 --- a/natsort/utils.py +++ b/natsort/utils.py @@ -804,7 +804,7 @@ def args_to_enum(**kwargs): msg = "The 'number_type' argument is deprecated as of 3.5.0 " msg += "and will be removed in 6.0.0, " msg += "please use 'alg=ns.FLOAT', 'alg=ns.INT', or 'alg=ns.VERSION'" - warn(msg, DeprecationWarning) + warn(msg, DeprecationWarning, stacklevel=3) alg |= ns.FLOAT * bool(kwargs["number_type"] is float) alg |= ns.INT * bool(kwargs["number_type"] in (int, None)) alg |= ns.SIGNED * (kwargs["number_type"] not in (float, None)) @@ -812,17 +812,18 @@ def args_to_enum(**kwargs): msg = "The 'signed' argument is deprecated as of 3.5.0 " msg += "and will be removed in 6.0.0, " msg += "please use 'alg=ns.SIGNED'." - warn(msg, DeprecationWarning) + warn(msg, DeprecationWarning, stacklevel=3) alg |= ns.SIGNED * bool(kwargs["signed"]) if "exp" in kwargs and kwargs["exp"] is not None: msg = "The 'exp' argument is deprecated as of 3.5.0 " msg += "and will be removed in 6.0.0, " msg += "please use 'alg=ns.NOEXP'." + warn(msg, DeprecationWarning, stacklevel=3) alg |= ns.NOEXP * (not kwargs["exp"]) if "as_path" in kwargs and kwargs["as_path"] is not None: msg = "The 'as_path' argument is deprecated as of 3.5.0 " msg += "and will be removed in 6.0.0, " msg += "please use 'alg=ns.PATH'." - warn(msg, DeprecationWarning) + warn(msg, DeprecationWarning, stacklevel=3) alg |= ns.PATH * kwargs["as_path"] return alg |