Skip to content

Commit

Permalink
Use stacklevel=2 in deprecation warnings to give callers better visib…
Browse files Browse the repository at this point in the history
…ility to the deprecated usage.
  • Loading branch information
jaraco committed Sep 17, 2018
1 parent dd3bdc8 commit fed3d69
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
2.5.1
=====

* Set stacklevel in deprecated functions for better
visibility of the call.

2.5
===

Expand Down
14 changes: 10 additions & 4 deletions jaraco/itertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ def __next__(self):
next = __next__

def GetCount(self):
warnings.warn("Use count attribute directly", DeprecationWarning)
warnings.warn(
"Use count attribute directly", DeprecationWarning,
stacklevel=2)
return self.count

# todo, factor out caching capability
Expand All @@ -461,7 +463,8 @@ def __init__(self, ignore_classes=six.string_types + (six.binary_type,)):
"""ignore_classes must include str, because if a string
is iterable, so is a single character, and the routine runs
into an infinite recursion"""
warnings.warn("Slated for removal", DeprecationWarning)
warnings.warn(
"Slated for removal", DeprecationWarning, stacklevel=2)
assert set(six.string_types) <= set(ignore_classes), (
'str must be in ignore_classes')
self.ignore_classes = ignore_classes
Expand Down Expand Up @@ -514,7 +517,10 @@ def flatten(subject, test=None):
>>> flatten([b'ab', b'c'])
[b'ab', b'c']
"""
warnings.warn("Use more_itertools.collapse instead", DeprecationWarning)
warnings.warn(
"Use more_itertools.collapse instead",
DeprecationWarning,
stacklevel=2)
return list(more.collapse(subject, base_type=(bytes,)))


Expand Down Expand Up @@ -980,7 +986,7 @@ def list_or_single(iterable):
>>> list_or_single(['a'])
'a'
"""
warnings.warn("Use maybe_single", DeprecationWarning)
warnings.warn("Use maybe_single", DeprecationWarning, stacklevel=2)
return maybe_single(list(iterable))


Expand Down

0 comments on commit fed3d69

Please sign in to comment.