Skip to content

Commit 12cf146

Browse files
withshubhjjlawren
andauthored
fix: code quality issues (pushingkarmaorg#670)
* Remove unnecessary use of comprehension * Remove unnecessary comprehension * Use literal syntax instead of function calls to create data structure * Pass string format arguments as logging method parameters * Remove unused imports * Remove unnecessary generator * Refactor `if` expression * fixed typo Co-authored-by: jjlawren <[email protected]> * Update tests/test_audio.py Co-authored-by: jjlawren <[email protected]>
1 parent 89d5241 commit 12cf146

File tree

8 files changed

+10
-16
lines changed

8 files changed

+10
-16
lines changed

plexapi/alert.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,4 @@ def _onError(self, *args): # pragma: no cover
8484
This is to support compatibility with current and previous releases of websocket-client.
8585
"""
8686
err = args[-1]
87-
log.error('AlertListener Error: %s' % err)
87+
log.error('AlertListener Error: %s', err)

plexapi/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ def __getattribute__(self, attr):
397397
clsname = self.__class__.__name__
398398
title = self.__dict__.get('title', self.__dict__.get('name'))
399399
objname = "%s '%s'" % (clsname, title) if title else clsname
400-
log.debug("Reloading %s for attr '%s'" % (objname, attr))
400+
log.debug("Reloading %s for attr '%s'", objname, attr)
401401
# Reload and return the value
402402
self.reload()
403403
return super(PlexPartialObject, self).__getattribute__(attr)
@@ -501,7 +501,7 @@ def delete(self):
501501
return self._server.query(self.key, method=self._server._session.delete)
502502
except BadRequest: # pragma: no cover
503503
log.error('Failed to delete %s. This could be because you '
504-
'havnt allowed items to be deleted' % self.key)
504+
'have not allowed items to be deleted', self.key)
505505
raise
506506

507507
def history(self, maxresults=9999999, mindate=None):

plexapi/library.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ def _cleanSearchFilter(self, category, value, libtype=None):
723723
result = set()
724724
choices = self.listChoices(category, libtype)
725725
lookup = {c.title.lower(): unquote(unquote(c.key)) for c in choices}
726-
allowed = set(c.key for c in choices)
726+
allowed = {c.key for c in choices}
727727
for item in value:
728728
item = str((item.id or item.tag) if isinstance(item, media.MediaTag) else item).lower()
729729
# find most logical choice(s) to use in url

plexapi/settings.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def _loadData(self, data):
4444

4545
def all(self):
4646
""" Returns a list of all :class:`~plexapi.settings.Setting` objects available. """
47-
return list(v for id, v in sorted(self._settings.items()))
47+
return [v for id, v in sorted(self._settings.items())]
4848

4949
def get(self, id):
5050
""" Return the :class:`~plexapi.settings.Setting` object with the specified id. """
@@ -102,7 +102,7 @@ class Setting(PlexObject):
102102
group (str): Group name this setting is categorized as.
103103
enumValues (list,dict): List or dictionary of valis values for this setting.
104104
"""
105-
_bool_cast = lambda x: True if x == 'true' or x == '1' else False
105+
_bool_cast = lambda x: bool(x == 'true' or x == '1')
106106
_bool_str = lambda x: str(x).lower()
107107
TYPES = {
108108
'bool': {'type': bool, 'cast': _bool_cast, 'tostr': _bool_str},

plexapi/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def threaded(callback, listargs):
176176
threads[-1].setDaemon(True)
177177
threads[-1].start()
178178
while not job_is_done_event.is_set():
179-
if all([not t.is_alive() for t in threads]):
179+
if all(not t.is_alive() for t in threads):
180180
break
181181
time.sleep(0.05)
182182

tests/test_history.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
# -*- coding: utf-8 -*-
2-
from datetime import datetime
3-
4-
import pytest
5-
from plexapi.exceptions import BadRequest, NotFound
6-
7-
from . import conftest as utils
82

93

104
def test_history_Movie(movie):

tests/test_video.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def test_video_Movie_upload_select_remove_subtitle(movie, subtitle):
134134
assert subname in subtitles
135135

136136
subtitleSelection = movie.subtitleStreams()[0]
137-
parts = [part for part in movie.iterParts()]
137+
parts = list(movie.iterParts())
138138
parts[0].setDefaultSubtitleStream(subtitleSelection)
139139
movie.reload()
140140

tools/plex-backupwatched.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _iter_items(section):
5151

5252
def backup_watched(plex, opts):
5353
""" Backup watched status to the specified filepath. """
54-
data = defaultdict(lambda: dict())
54+
data = defaultdict(lambda: {})
5555
for section in _iter_sections(plex, opts):
5656
print('Fetching watched status for %s..' % section.title)
5757
skey = section.title.lower()
@@ -70,7 +70,7 @@ def restore_watched(plex, opts):
7070
with open(opts.filepath, 'r') as handle:
7171
source = json.load(handle)
7272
# Find the differences
73-
differences = defaultdict(lambda: dict())
73+
differences = defaultdict(lambda: {})
7474
for section in _iter_sections(plex, opts):
7575
print('Finding differences in %s..' % section.title)
7676
skey = section.title.lower()

0 commit comments

Comments
 (0)