From 43c27c8e6fb71da9dde05d28a78f4f1d50ff35f0 Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Wed, 17 Feb 2021 08:13:43 +0000 Subject: [PATCH 1/9] Remove unnecessary use of comprehension --- .deepsource.toml | 12 ++++++++++++ tests/test_video.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml new file mode 100644 index 000000000..52933f17a --- /dev/null +++ b/.deepsource.toml @@ -0,0 +1,12 @@ +version = 1 + +test_patterns = ["tests/**/test_*.py"] + +exclude_patterns = ["docs/**"] + +[[analyzers]] +name = "python" +enabled = true + + [analyzers.meta] + runtime_version = "3.x.x" diff --git a/tests/test_video.py b/tests/test_video.py index 5e14cae83..dc979cbc1 100644 --- a/tests/test_video.py +++ b/tests/test_video.py @@ -129,7 +129,7 @@ def test_video_Movie_upload_select_remove_subtitle(movie, subtitle): assert subname in subtitles subtitleSelection = movie.subtitleStreams()[0] - parts = [part for part in movie.iterParts()] + parts = list(movie.iterParts()) parts[0].setDefaultSubtitleStream(subtitleSelection) movie.reload() From 3509fb979e0ab506d066957408f0d42e3c192dd1 Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Wed, 17 Feb 2021 08:16:50 +0000 Subject: [PATCH 2/9] Remove unnecessary comprehension --- plexapi/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plexapi/utils.py b/plexapi/utils.py index a56d87abe..3ec68c759 100644 --- a/plexapi/utils.py +++ b/plexapi/utils.py @@ -177,7 +177,7 @@ def threaded(callback, listargs): threads[-1].setDaemon(True) threads[-1].start() while not job_is_done_event.is_set(): - if all([not t.is_alive() for t in threads]): + if all(not t.is_alive() for t in threads): break time.sleep(0.05) From 3b2db28b6c9d3afe9bbd6dca42dac66a10153bf8 Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Wed, 17 Feb 2021 08:18:10 +0000 Subject: [PATCH 3/9] Use literal syntax instead of function calls to create data structure --- tools/plex-backupwatched.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/plex-backupwatched.py b/tools/plex-backupwatched.py index 5307e3125..4cacd1160 100755 --- a/tools/plex-backupwatched.py +++ b/tools/plex-backupwatched.py @@ -51,7 +51,7 @@ def _iter_items(section): def backup_watched(plex, opts): """ Backup watched status to the specified filepath. """ - data = defaultdict(lambda: dict()) + data = defaultdict(lambda: {}) for section in _iter_sections(plex, opts): print('Fetching watched status for %s..' % section.title) skey = section.title.lower() @@ -70,7 +70,7 @@ def restore_watched(plex, opts): with open(opts.filepath, 'r') as handle: source = json.load(handle) # Find the differences - differences = defaultdict(lambda: dict()) + differences = defaultdict(lambda: {}) for section in _iter_sections(plex, opts): print('Finding differences in %s..' % section.title) skey = section.title.lower() From 88be0b0c529589cac0cf290f53cff8b504d3207a Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Wed, 17 Feb 2021 08:19:51 +0000 Subject: [PATCH 4/9] Pass string format arguments as logging method parameters --- plexapi/alert.py | 2 +- plexapi/base.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plexapi/alert.py b/plexapi/alert.py index bf6e5394f..9e0310fd5 100644 --- a/plexapi/alert.py +++ b/plexapi/alert.py @@ -84,4 +84,4 @@ def _onError(self, *args): # pragma: no cover This is to support compatibility with current and previous releases of websocket-client. """ err = args[-1] - log.error('AlertListener Error: %s' % err) + log.error('AlertListener Error: %s', err) diff --git a/plexapi/base.py b/plexapi/base.py index 92c00bf92..3d5738495 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -397,7 +397,7 @@ def __getattribute__(self, attr): clsname = self.__class__.__name__ title = self.__dict__.get('title', self.__dict__.get('name')) objname = "%s '%s'" % (clsname, title) if title else clsname - log.debug("Reloading %s for attr '%s'" % (objname, attr)) + log.debug("Reloading %s for attr '%s'", objname, attr) # Reload and return the value self.reload() return super(PlexPartialObject, self).__getattribute__(attr) @@ -501,7 +501,7 @@ def delete(self): return self._server.query(self.key, method=self._server._session.delete) except BadRequest: # pragma: no cover log.error('Failed to delete %s. This could be because you ' - 'havnt allowed items to be deleted' % self.key) + 'havnt allowed items to be deleted', self.key) raise def history(self, maxresults=9999999, mindate=None): From 89028d56fb583c8a67332a2203b61d4a7f0487ff Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Wed, 17 Feb 2021 08:28:37 +0000 Subject: [PATCH 5/9] Remove unused imports --- tests/test_audio.py | 1 - tests/test_history.py | 6 ------ 2 files changed, 7 deletions(-) diff --git a/tests/test_audio.py b/tests/test_audio.py index 13ab8066a..be8fd80ce 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from datetime import datetime from . import conftest as utils from . import test_mixins diff --git a/tests/test_history.py b/tests/test_history.py index af5c65fef..bc23eb1bb 100644 --- a/tests/test_history.py +++ b/tests/test_history.py @@ -1,10 +1,4 @@ # -*- coding: utf-8 -*- -from datetime import datetime - -import pytest -from plexapi.exceptions import BadRequest, NotFound - -from . import conftest as utils def test_history_Movie(movie): From 5eb92393ea72958daeb53bbb6148db799e0f443f Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Wed, 17 Feb 2021 08:30:55 +0000 Subject: [PATCH 6/9] Remove unnecessary generator --- plexapi/library.py | 2 +- plexapi/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plexapi/library.py b/plexapi/library.py index 8a6413f6a..c87770810 100644 --- a/plexapi/library.py +++ b/plexapi/library.py @@ -725,7 +725,7 @@ def _cleanSearchFilter(self, category, value, libtype=None): result = set() choices = self.listChoices(category, libtype) lookup = {c.title.lower(): unquote(unquote(c.key)) for c in choices} - allowed = set(c.key for c in choices) + allowed = {c.key for c in choices} for item in value: item = str((item.id or item.tag) if isinstance(item, media.MediaTag) else item).lower() # find most logical choice(s) to use in url diff --git a/plexapi/settings.py b/plexapi/settings.py index 8416f8718..623215136 100644 --- a/plexapi/settings.py +++ b/plexapi/settings.py @@ -44,7 +44,7 @@ def _loadData(self, data): def all(self): """ Returns a list of all :class:`~plexapi.settings.Setting` objects available. """ - return list(v for id, v in sorted(self._settings.items())) + return [v for id, v in sorted(self._settings.items())] def get(self, id): """ Return the :class:`~plexapi.settings.Setting` object with the specified id. """ From 4d0ed8119d599261c68d613f1766da49d08fdb43 Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Wed, 17 Feb 2021 08:32:02 +0000 Subject: [PATCH 7/9] Refactor `if` expression --- .deepsource.toml | 12 ------------ plexapi/settings.py | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 .deepsource.toml diff --git a/.deepsource.toml b/.deepsource.toml deleted file mode 100644 index 52933f17a..000000000 --- a/.deepsource.toml +++ /dev/null @@ -1,12 +0,0 @@ -version = 1 - -test_patterns = ["tests/**/test_*.py"] - -exclude_patterns = ["docs/**"] - -[[analyzers]] -name = "python" -enabled = true - - [analyzers.meta] - runtime_version = "3.x.x" diff --git a/plexapi/settings.py b/plexapi/settings.py index 623215136..734cc1198 100644 --- a/plexapi/settings.py +++ b/plexapi/settings.py @@ -102,7 +102,7 @@ class Setting(PlexObject): group (str): Group name this setting is categorized as. enumValues (list,dict): List or dictionary of valis values for this setting. """ - _bool_cast = lambda x: True if x == 'true' or x == '1' else False + _bool_cast = lambda x: bool(x == 'true' or x == '1') _bool_str = lambda x: str(x).lower() TYPES = { 'bool': {'type': bool, 'cast': _bool_cast, 'tostr': _bool_str}, From 411d8fe6469f037f6afc1b24c641815fe90dac44 Mon Sep 17 00:00:00 2001 From: Shubhendra Singh Chauhan Date: Wed, 24 Feb 2021 22:52:18 +0530 Subject: [PATCH 8/9] fixed typo Co-authored-by: jjlawren --- plexapi/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plexapi/base.py b/plexapi/base.py index 3d5738495..cf10a73ea 100644 --- a/plexapi/base.py +++ b/plexapi/base.py @@ -501,7 +501,7 @@ def delete(self): return self._server.query(self.key, method=self._server._session.delete) except BadRequest: # pragma: no cover log.error('Failed to delete %s. This could be because you ' - 'havnt allowed items to be deleted', self.key) + 'have not allowed items to be deleted', self.key) raise def history(self, maxresults=9999999, mindate=None): From 65bf65ef85a3591f78e1ac05a5fe2d3e4fcd3e0f Mon Sep 17 00:00:00 2001 From: jjlawren Date: Wed, 24 Feb 2021 11:54:03 -0600 Subject: [PATCH 9/9] Update tests/test_audio.py --- tests/test_audio.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_audio.py b/tests/test_audio.py index 89a2ef752..d6a0d24bf 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - from . import conftest as utils from . import test_mixins