From e0542c2e4a685436fc2aefd6de093f839950745e Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Fri, 15 Mar 2013 20:20:35 +0100 Subject: [PATCH] Fix comparisons to None Diff checked manually. autopep8 -a -ir -j2 --select=E711 . This required the "agressive" option because it can change code behavior. --- contrib/downloadboob/downloadboob.py | 2 +- modules/boursorama/pages/accounts_list.py | 2 +- modules/cic/browser.py | 2 +- modules/cragr/browser.py | 2 +- modules/creditmutuel/browser.py | 2 +- modules/imdb/backend.py | 2 +- modules/imdb/browser.py | 2 +- modules/imdb/pages.py | 8 ++++---- modules/imdb/test.py | 4 ++-- modules/isohunt/pages/torrents.py | 6 +++--- modules/parolesmania/pages.py | 2 +- modules/societegenerale/pages/accounts_list.py | 2 +- weboob/applications/qcineoob/main_window.py | 12 ++++++------ weboob/tools/capabilities/messages/genericArticle.py | 6 +++--- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/contrib/downloadboob/downloadboob.py b/contrib/downloadboob/downloadboob.py index 49e9fcebea..a343a0eddc 100755 --- a/contrib/downloadboob/downloadboob.py +++ b/contrib/downloadboob/downloadboob.py @@ -123,7 +123,7 @@ def is_excluded(self, title, title_exclude): def id_regexp_matched(self, video_id, id_regexp): if id_regexp: - return re.search(id_regexp, video_id) != None + return re.search(id_regexp, video_id) is not None return True def get_filename(self, video, relative=False): diff --git a/modules/boursorama/pages/accounts_list.py b/modules/boursorama/pages/accounts_list.py index 677b4bf0ae..6095e8dc6b 100644 --- a/modules/boursorama/pages/accounts_list.py +++ b/modules/boursorama/pages/accounts_list.py @@ -60,7 +60,7 @@ def get_list(self): elif td.attrib.get('class', '') == 'account-total': span = td.find('span') - if span == None: + if span is None: balance = td.text else: balance = span.text diff --git a/modules/cic/browser.py b/modules/cic/browser.py index c1a045262d..f04b291c12 100644 --- a/modules/cic/browser.py +++ b/modules/cic/browser.py @@ -153,7 +153,7 @@ def transfer(self, account, to, amount, reason=None): self['IDB'] = [account[-1]] self['ICR'] = [to[-1]] self['MTTVIR'] = '%s' % str(amount).replace('.', ',') - if reason != None: + if reason is not None: self['LIBDBT'] = reason self['LIBCRT'] = reason self.submit() diff --git a/modules/cragr/browser.py b/modules/cragr/browser.py index f8e5ff120c..db23d0f378 100644 --- a/modules/cragr/browser.py +++ b/modules/cragr/browser.py @@ -228,7 +228,7 @@ def do_transfer(self, account, to, amount, reason=None): self['numCompteBeneficiaire'] = ['%s' % self.dict_find_value(target_accounts, to)] self['montantPartieEntiere'] = '%s' % amount_euros self['montantPartieDecimale'] = '%02d' % amount_cents - if reason != None: + if reason is not None: self['libelle'] = reason self.submit() diff --git a/modules/creditmutuel/browser.py b/modules/creditmutuel/browser.py index 3ea6e7fcad..bd064d6d47 100644 --- a/modules/creditmutuel/browser.py +++ b/modules/creditmutuel/browser.py @@ -153,7 +153,7 @@ def transfer(self, account, to, amount, reason=None): self['IDB'] = [account[-1]] self['ICR'] = [to[-1]] self['MTTVIR'] = '%s' % str(amount).replace('.', ',') - if reason != None: + if reason is not None: self['LIBDBT'] = reason self['LIBCRT'] = reason self.submit() diff --git a/modules/imdb/backend.py b/modules/imdb/backend.py index c695f3bc84..cbe258614f 100644 --- a/modules/imdb/backend.py +++ b/modules/imdb/backend.py @@ -74,7 +74,7 @@ def fill_person(self, person, fields): or 'death_date' in fields or 'nationality' in fields\ or 'short_biography' in fields or 'roles' in fields\ or 'birth_date' in fields or 'thumbnail_url' in fields\ - or 'gender' in fields or fields == None: + or 'gender' in fields or fields is None: per = self.get_person(person.id) person.real_name = per.real_name person.birth_date = per.birth_date diff --git a/modules/imdb/browser.py b/modules/imdb/browser.py index 82fef92cad..7d6a985333 100644 --- a/modules/imdb/browser.py +++ b/modules/imdb/browser.py @@ -89,7 +89,7 @@ def iter_persons(self, pattern): def get_movie(self, id): res = self.readurl('http://imdbapi.org/?id=%s&type=json&plot=simple&episode=1&lang=en-US&aka=full&release=simple&business=0&tech=0' % id ) - if res != None: + if res is not None: jres = json.loads(res) else: return None diff --git a/modules/imdb/pages.py b/modules/imdb/pages.py index 0c31711109..cdf11ca641 100644 --- a/modules/imdb/pages.py +++ b/modules/imdb/pages.py @@ -37,7 +37,7 @@ def get_movie_releases(self,country_filter): for a in links: href = a.attrib.get('href','') if href.strip('/').split('/')[0] == 'calendar' and\ - (country_filter == None or href.split('region=')[-1].lower() == country_filter): + (country_filter is None or href.split('region=')[-1].lower() == country_filter): country = a.text td_date = self.parser.select(a.getparent().getparent().getparent(),'td')[1] date_links = self.parser.select(td_date,'a') @@ -73,7 +73,7 @@ class MovieCrewPage(BasePage): ''' Page listing all the persons related to a movie ''' def iter_persons(self, role_filter=None): - if (role_filter == None or (role_filter != None and role_filter == 'actor')): + if (role_filter is None or (role_filter is not None and role_filter == 'actor')): tables = self.parser.select(self.document.getroot(),'table.cast') if len(tables) > 0: table = tables[0] @@ -97,7 +97,7 @@ def iter_persons(self, role_filter=None): for gloss_link in self.parser.select(self.document.getroot(),'table[cellspacing=1] h5 a'): role = gloss_link.attrib.get('name','').rstrip('s') - if (role_filter == None or (role_filter != None and role == role_filter)): + if (role_filter is None or (role_filter is not None and role == role_filter)): tbody = gloss_link.getparent().getparent().getparent().getparent() for line in self.parser.select(tbody,'tr')[1:]: for a in self.parser.select(line,'a'): @@ -217,7 +217,7 @@ def get_roles(self): def iter_movies(self, role_filter=None): for role_div in self.parser.select(self.document.getroot(),'div.filmo'): role = self.parser.select(role_div,'h5 a',1).text.replace(':','') - if (role_filter == None or (role_filter != None and role.lower().strip() == role_filter))\ + if (role_filter is None or (role_filter is not None and role.lower().strip() == role_filter))\ and role != 'In Development': for a in self.parser.select(role_div,'ol > li > a'): id = a.attrib.get('href','').strip('/').split('/')[-1] diff --git a/modules/imdb/test.py b/modules/imdb/test.py index 80a469726a..aae7ba7168 100644 --- a/modules/imdb/test.py +++ b/modules/imdb/test.py @@ -59,9 +59,9 @@ def test_person_movies(self): def test_get_person_biography(self): bio = self.backend.get_person_biography('nm0223033') assert bio != '' - assert bio != None + assert bio is not None def test_get_movie_releases(self): rel = self.backend.get_movie_releases('tt0079980') assert rel != '' - assert rel != None + assert rel is not None diff --git a/modules/isohunt/pages/torrents.py b/modules/isohunt/pages/torrents.py index 0425787243..4b01a2bf9f 100644 --- a/modules/isohunt/pages/torrents.py +++ b/modules/isohunt/pages/torrents.py @@ -53,9 +53,9 @@ def iter_torrents(self): size = float(size[:-3]) sseed = tr.getchildren()[4].text sleech = tr.getchildren()[5].text - if sseed != None and sseed != "": + if sseed is not None and sseed != "": seed = int(sseed) - if sleech != None and sleech != "": + if sleech is not None and sleech != "": leech = int(sleech) url = u'https://isohunt.com/download/%s/mon_joli_torrent.torrent' % idt torrent = Torrent(idt, title) @@ -101,7 +101,7 @@ def get_torrent(self, id): if p.attrib.get('style', '') == 'line-height:1.2em;margin-top:1.8em': count_p_found += 1 if count_p_found == 1: - if p.getchildren()[1].tail != None: + if p.getchildren()[1].tail is not None: description = unicode(p.getchildren()[1].tail) if count_p_found == 2: if p.getchildren()[0].text == 'Directory:': diff --git a/modules/parolesmania/pages.py b/modules/parolesmania/pages.py index 18a85be03f..b35b946796 100644 --- a/modules/parolesmania/pages.py +++ b/modules/parolesmania/pages.py @@ -40,7 +40,7 @@ def iter_lyrics(self): class ArtistSongsPage(BasePage): def iter_lyrics(self,artist=None): - if artist == None: + if artist is None: artist = self.parser.select(self.document.getroot(),'head > title',1).text.replace('Paroles ','') for link in self.parser.select(self.document.getroot(),'div#albums a'): href = link.attrib.get('href','') diff --git a/modules/societegenerale/pages/accounts_list.py b/modules/societegenerale/pages/accounts_list.py index 1f7bc31021..bc7f3d5de9 100644 --- a/modules/societegenerale/pages/accounts_list.py +++ b/modules/societegenerale/pages/accounts_list.py @@ -66,7 +66,7 @@ def get_list(self): elif td.attrib.get('headers', '') == 'Solde': balance = td.find('div').text if td.find('div') is not None else None - if balance != None: + if balance is not None: account.currency = account.get_currency(balance) balance = FrenchTransaction.clean_amount(balance) account.balance = Decimal(balance) diff --git a/weboob/applications/qcineoob/main_window.py b/weboob/applications/qcineoob/main_window.py index 44095f5612..e4c6dce406 100644 --- a/weboob/applications/qcineoob/main_window.py +++ b/weboob/applications/qcineoob/main_window.py @@ -109,7 +109,7 @@ def loadSearchHistory(self): f=codecs.open(history_path,'r','utf-8') conf_hist = f.read() f.close() - if conf_hist != None and conf_hist.strip() != '': + if conf_hist is not None and conf_hist.strip() != '': result = conf_hist.strip().split('\n') return result @@ -140,7 +140,7 @@ def doAction(self, description, fun, args): and save it in the action history ''' self.ui.currentActionLabel.setText(description) - if self.action_history['last_action'] != None: + if self.action_history['last_action'] is not None: self.action_history['action_list'].append(self.action_history['last_action']) self.ui.backButton.setToolTip(self.action_history['last_action']['description']) self.ui.backButton.show() @@ -246,7 +246,7 @@ def addMovie(self, backend, movie): def displayMovie(self, movie, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) - if self.current_info_widget != None: + if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() @@ -289,7 +289,7 @@ def addPerson(self, backend, person): def displayPerson(self, person, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) - if self.current_info_widget != None: + if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() @@ -332,7 +332,7 @@ def addTorrent(self, backend, torrent): def displayTorrent(self, torrent, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) - if self.current_info_widget != None: + if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() @@ -375,7 +375,7 @@ def addSubtitle(self, backend, subtitle): def displaySubtitle(self, subtitle, backend): self.ui.stackedWidget.setCurrentWidget(self.ui.info_page) - if self.current_info_widget != None: + if self.current_info_widget is not None: self.ui.info_content.layout().removeWidget(self.current_info_widget) self.current_info_widget.hide() self.current_info_widget.deleteLater() diff --git a/weboob/tools/capabilities/messages/genericArticle.py b/weboob/tools/capabilities/messages/genericArticle.py index 14731d19db..f27eb678ba 100644 --- a/weboob/tools/capabilities/messages/genericArticle.py +++ b/weboob/tools/capabilities/messages/genericArticle.py @@ -115,7 +115,7 @@ def get_title(self): self.element_title_selector, 1).text_content().strip() except AttributeError: - if self.main_div == None: + if self.main_div is None: #TODO: Mettre un warning return self.__article.title else: @@ -132,7 +132,7 @@ def get_element_body(self): except BrokenPageError: raise NoBodyElement("no body on %s" % (self.browser)) except AttributeError: - if self.main_div == None: + if self.main_div is None: raise NoneMainDiv("main_div is none on %s" % (self.browser)) else: raise @@ -143,7 +143,7 @@ def get_element_author(self): except BrokenPageError: raise NoAuthorElement() except AttributeError: - if self.main_div == None: + if self.main_div is None: raise NoneMainDiv("main_div is none on %s" % (self.browser)) else: raise -- GitLab