diff --git a/CHANGES.md b/CHANGES.md index dc0f5f5c..e5107f87 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,8 @@ * Change remove calls to legacy py2 fix encoding function * Change requirements for pure py3 * Change codebase cleanups +* Change improve perf by using generators with `any` + [develop changelog] diff --git a/gui/slick/interfaces/default/inc_top.tmpl b/gui/slick/interfaces/default/inc_top.tmpl index 2416f49f..11f1e410 100644 --- a/gui/slick/interfaces/default/inc_top.tmpl +++ b/gui/slick/interfaces/default/inc_top.tmpl @@ -105,7 +105,7 @@ #except #pass #end try -#if not any([x in $body_attr for x in ['back-art', 'pro', 'ii']]) +#if not any(x in $body_attr for x in ['back-art', 'pro', 'ii']) #set $parts = $body_attr.split('class="') #set $body_attr = ('class="%s '.join($parts), $parts[0] + ' class="%s"')[1 == len($parts)] % {0: '', 1: 'pro', 2: 'pro ii'}.get(getattr($sickgear, 'DISPLAY_SHOW_VIEWMODE', 0)) #end if diff --git a/lib/plex/plex.py b/lib/plex/plex.py index 26f5436c..18996ce7 100644 --- a/lib/plex/plex.py +++ b/lib/plex/plex.py @@ -381,7 +381,7 @@ class Plex(object): section_path = re.sub(r'[/\\]+', '/', section.find('Location').get('path').lower()) section_path = re.sub(r'^(.{,2})[/\\]', '', section_path) - if not any([section_path in path for path in self.section_filter_path]): + if not any(section_path in path for path in self.section_filter_path): continue if section.get('key') not in self.ignore_sections \ diff --git a/sickgear/classes.py b/sickgear/classes.py index a10360d0..f6e5e564 100644 --- a/sickgear/classes.py +++ b/sickgear/classes.py @@ -195,7 +195,7 @@ class ShowInfoFilter(object): return isinstance(show_info, dict) \ and 'seriesname' in show_info \ and isinstance(show_info['seriesname'], string_types) \ - and any([x.search(show_info['seriesname']) for x in self.bad_names]) + and any(x.search(show_info['seriesname']) for x in self.bad_names) @staticmethod def _fix_firstaired(show_info): diff --git a/sickgear/common.py b/sickgear/common.py index ce713630..e66b946a 100644 --- a/sickgear/common.py +++ b/sickgear/common.py @@ -745,9 +745,9 @@ class NeededQualities(object): else: if not self.need_sd and min(wanted_qualities) <= NeededQualities.max_sd: self.need_sd = True - if not self.need_hd and any([i in NeededQualities.hd_qualities for i in wanted_qualities]): + if not self.need_hd and any(i in NeededQualities.hd_qualities for i in wanted_qualities): self.need_hd = True - if not self.need_webdl and any([i in NeededQualities.webdl_qualities for i in wanted_qualities]): + if not self.need_webdl and any(i in NeededQualities.webdl_qualities for i in wanted_qualities): self.need_webdl = True if not self.need_uhd and max(wanted_qualities) > NeededQualities.max_hd: self.need_uhd = True diff --git a/sickgear/providers/generic.py b/sickgear/providers/generic.py index 126cc747..eca6d7a2 100644 --- a/sickgear/providers/generic.py +++ b/sickgear/providers/generic.py @@ -501,8 +501,8 @@ class GenericProvider(object): if time_left > datetime.timedelta(seconds=0): if log_warning: # Ensure provider name output (e.g. when displaying config/provs) instead of e.g. thread "Tornado" - prepend = ('[%s] :: ' % self.name, '')[any([x.name in threading.current_thread().name - for x in sickgear.providers.sorted_sources()])] + prepend = ('[%s] :: ' % self.name, '')[any(x.name in threading.current_thread().name + for x in sickgear.providers.sorted_sources())] logger.log('%sToo many requests reached at %s, waiting for %s' % ( prepend, self.fmt_delta(self.tmr_limit_time), self.fmt_delta(time_left)), logger.WARNING) return use_tmr_limit @@ -1009,9 +1009,9 @@ class GenericProvider(object): headers = [re.sub( r'\s+', '', - ((any([cell.get_text()]) and any([rc[x].search(cell.get_text()) for x in iterkeys(rc)]) and cell.get_text()) - or (cell.attrs.get('id') and any([rc[x].search(cell['id']) for x in iterkeys(rc)]) and cell['id']) - or (cell.attrs.get('title') and any([rc[x].search(cell['title']) for x in iterkeys(rc)]) and cell['title']) + ((any([cell.get_text()]) and any(rc[x].search(cell.get_text()) for x in iterkeys(rc)) and cell.get_text()) + or (cell.attrs.get('id') and any(rc[x].search(cell['id']) for x in iterkeys(rc)) and cell['id']) + or (cell.attrs.get('title') and any(rc[x].search(cell['title']) for x in iterkeys(rc)) and cell['title']) or next(iter(set(filter(lambda rz: any([rz]), [ next(iter(set(filter(lambda ry: any([ry]), [ cell.find(tag, **p) for p in [{attr: rc[x]} for x in iterkeys(rc)]]))), {}).get(attr) @@ -1932,7 +1932,7 @@ class TorrentProvider(GenericProvider): url_list = list(map(lambda u: '%s/' % u.rstrip('/'), url_list)) last_url, expire = sickgear.PROVIDER_HOMES.get(self.get_id(), ('', None)) url_drop = (url_exclude or []) + getattr(self, 'url_drop', []) - if url_drop and any([url in last_url for url in url_drop]): # deprecate url + if url_drop and any(url in last_url for url in url_drop): # deprecate url last_url = '' if 'site down' == last_url: diff --git a/sickgear/providers/newznab.py b/sickgear/providers/newznab.py index fc701941..2fe12d6a 100644 --- a/sickgear/providers/newznab.py +++ b/sickgear/providers/newznab.py @@ -911,9 +911,9 @@ class NewznabProvider(generic.NZBProvider): # category ids cat = [] if 'Episode' == mode or 'Season' == mode: - if not (any([x in params for x in - [v for c, v in iteritems(self.caps) - if c not in [NewznabConstants.SEARCH_EPISODE, NewznabConstants.SEARCH_SEASON]]])): + if not (any(x in params for x in + [v for c, v in iteritems(self.caps) + if c not in [NewznabConstants.SEARCH_EPISODE, NewznabConstants.SEARCH_SEASON]])): logger.log('Show is missing either an id or search term for search') continue @@ -938,7 +938,7 @@ class NewznabProvider(generic.NZBProvider): request_params = base_params.copy() # if ('Propers' == mode or 'nzbs_org' == self.get_id()) \ if 'Propers' == mode \ - and 'q' in params and not (any([x in params for x in ['season', 'ep']])): + and 'q' in params and not (any(x in params for x in ['season', 'ep'])): request_params['t'] = 'search' request_params.update(params) @@ -1048,10 +1048,10 @@ class NewznabProvider(generic.NZBProvider): if exit_log: self._log_search(mode, len(results), search_url) - if not try_all_searches and any([x in request_params for x in [ + if not try_all_searches and any(x in request_params for x in [ v for c, v in iteritems(self.caps) if c not in [NewznabConstants.SEARCH_EPISODE, NewznabConstants.SEARCH_SEASON, - NewznabConstants.SEARCH_TEXT]]]) and len(results): + NewznabConstants.SEARCH_TEXT]]) and len(results): break return results, n_spaces diff --git a/sickgear/scene_exceptions.py b/sickgear/scene_exceptions.py index b7ee204a..ceaa42d4 100644 --- a/sickgear/scene_exceptions.py +++ b/sickgear/scene_exceptions.py @@ -583,6 +583,6 @@ def has_abs_episodes(ep_obj=None, name=None): :return: :rtype: bool """ - return any([(name or ep_obj.show_obj.name or '').lower().startswith(x.lower()) for x in [ + return any((name or ep_obj.show_obj.name or '').lower().startswith(x.lower()) for x in [ 'The Eighties', 'The Making of the Mob', 'The Night Of', 'Roots 2016', 'Trepalium' - ]]) + ]) diff --git a/sickgear/tv.py b/sickgear/tv.py index 8a6c274f..23641792 100644 --- a/sickgear/tv.py +++ b/sickgear/tv.py @@ -3042,7 +3042,7 @@ class TVShow(TVShowBase): page_url = 'https://www.imdb.com/title/{0}/'.format(imdb_id) try: response = requests.head(page_url, allow_redirects=True) - if response.history and any([h for h in response.history if 301 == h.status_code]): + if response.history and any(h for h in response.history if 301 == h.status_code): return helpers.parse_imdb_id(response.url) except (BaseException, Exception): pass diff --git a/sickgear/webapi.py b/sickgear/webapi.py index 40246086..b91e1625 100644 --- a/sickgear/webapi.py +++ b/sickgear/webapi.py @@ -600,7 +600,7 @@ class ApiCall(object): elif isinstance(value, string_types): if '|' in value: li = [int(v) for v in value.split('|')] - if any([not isinstance(v, integer_types) for v in li]): + if any(not isinstance(v, integer_types) for v in li): error = True else: value = li @@ -610,7 +610,7 @@ class ApiCall(object): error = True else: li = value.split('|') - if any([sub_type is not type(v) for v in li]): + if any(sub_type is not type(v) for v in li): error = True else: value = li