Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecation warnings #669

Merged
merged 3 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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