Skip to content

Commit

Permalink
Merge pull request #669 from JonnyWong16/bugfix/warnings
Browse files Browse the repository at this point in the history
Fix deprecation warnings
  • Loading branch information
JonnyWong16 authored Feb 24, 2021
2 parents 2954fdb + b10420f commit 0b2f397
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion plexapi/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _loadData(self, data):
self.updatedAt = utils.toDatetime(data.attrib.get('updatedAt'))

@property
@deprecated('use "items" instead')
@deprecated('use "items" instead', stacklevel=3)
def children(self):
return self.items()

Expand Down
5 changes: 2 additions & 3 deletions plexapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
tqdm = None

log = logging.getLogger('plexapi')
warnings.simplefilter('default', category=DeprecationWarning)

# Search Types - Plex uses these to filter specific media types when searching.
# Library Types - Populated at runtime
Expand Down Expand Up @@ -467,15 +466,15 @@ def base64str(text):
return base64.b64encode(text.encode('utf-8')).decode('utf-8')


def deprecated(message):
def deprecated(message, stacklevel=2):
def decorator(func):
"""This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used."""
@functools.wraps(func)
def wrapper(*args, **kwargs):
msg = 'Call to deprecated function or method "%s", %s.' % (func.__name__, message)
warnings.warn(msg, category=DeprecationWarning, stacklevel=3)
warnings.warn(msg, category=DeprecationWarning, stacklevel=stacklevel)
log.warning(msg)
return func(*args, **kwargs)
return wrapper
Expand Down

0 comments on commit 0b2f397

Please sign in to comment.