jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/750723 )
Change subject: [fix] Solve some deepsource antipattern issues ......................................................................
[fix] Solve some deepsource antipattern issues
https://deepsource.io/gh/xqt/pwb/issues?page=2&category=antipattern&...
Change-Id: I9c3d179a5a23418e9acde199a9d1671c74af9239 --- M pywikibot/config.py M scripts/reflinks.py M scripts/solve_disambiguation.py M tests/aspects.py M tests/interwikimap_tests.py M tests/oauth_tests.py M tests/paraminfo_tests.py 7 files changed, 19 insertions(+), 26 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/config.py b/pywikibot/config.py index 1a7819e..259520a 100644 --- a/pywikibot/config.py +++ b/pywikibot/config.py @@ -540,7 +540,7 @@ # ############# EXTERNAL EDITOR SETTINGS ############## # The command for the editor you want to use. If set to None, a simple Tkinter # editor will be used. -editor = os.environ.get('EDITOR', None) +editor = os.environ.get('EDITOR')
# Warning: DO NOT use an editor which doesn't support Unicode to edit pages! # You will BREAK non-ASCII symbols! diff --git a/scripts/reflinks.py b/scripts/reflinks.py index b3e425e..3623aec 100755 --- a/scripts/reflinks.py +++ b/scripts/reflinks.py @@ -720,9 +720,8 @@ new_text = new_text.replace(match.group(), repl)
# Add <references/> when needed, but ignore templates ! - if page.namespace != 10: - if self.norefbot.lacksReferences(new_text): - new_text = self.norefbot.addReferences(new_text) + if page.namespace != 10 and self.norefbot.lacksReferences(new_text): + new_text = self.norefbot.addReferences(new_text)
new_text = self.deduplicator.process(new_text) old_text = page.text diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py index 16506b1..fa380e2 100755 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -686,10 +686,9 @@ # Currently scripts may have its own options set added_keys = [] for key in keys: - if key != 'generator': - if key not in self.available_options: - added_keys.append(key) - self.available_options[key] = self.disambig_options[key] + if key != 'generator' and key not in self.available_options: + added_keys.append(key) + self.available_options[key] = self.disambig_options[key] if added_keys: pywikibot.warning("""\ The following keys were added to available_options: @@ -1285,9 +1284,9 @@ ) gen = pagegenerators.PreloadingGenerator(gen) for ref_page in gen: - if not self.primaryIgnoreManager.isIgnored(ref_page): - if not self.treat_links(ref_page, page): - break # next disambig + if not self.primaryIgnoreManager.isIgnored(ref_page) \ + and not self.treat_links(ref_page, page): + break # next disambig
# clear alternatives before working on next disambiguation page self.opt.pos = [] diff --git a/tests/aspects.py b/tests/aspects.py index dc9da6e..cab9da7 100644 --- a/tests/aspects.py +++ b/tests/aspects.py @@ -729,12 +729,11 @@ # test class dependencies are declarative, this requires the # test writer explicitly sets 'site=False' so code reviewers # check that the script invoked by pwb will not load a site. - if dct.get('pwb'): - if 'site' not in dct: - raise Exception( - '{}: Test classes using pwb must set "site"; add ' - 'site=False if the test script will not use a site' - .format(name)) + if dct.get('pwb') and 'site' not in dct: + raise Exception( + '{}: Test classes using pwb must set "site"; add ' + 'site=False if the test script will not use a site' + .format(name))
# If the 'site' attribute is a false value, # remove it so it matches 'not site' in pytest. diff --git a/tests/interwikimap_tests.py b/tests/interwikimap_tests.py index 47fae45..a96597c 100644 --- a/tests/interwikimap_tests.py +++ b/tests/interwikimap_tests.py @@ -99,10 +99,6 @@ iw_site = site.interwiki(prefix) self.assertEqual(iw_site.family, site.family)
- def test_interwiki_prefix(self, key): - """Test site.interwiki_prefix method.""" - self.assertTrue(True) -
class TestInterwikiMapPrefix(TestCase):
diff --git a/tests/oauth_tests.py b/tests/oauth_tests.py index e33821e..7dc8556 100644 --- a/tests/oauth_tests.py +++ b/tests/oauth_tests.py @@ -26,8 +26,8 @@ def _get_oauth_tokens(self): """Get valid OAuth tokens from environment variables.""" tokens_env = 'OAUTH_TOKENS_' + self.family.upper() - tokens = os.environ.get(tokens_env + '_' + self.code.upper(), None) - tokens = tokens or os.environ.get(tokens_env, None) + tokens = os.environ.get(tokens_env + '_' + self.code.upper()) + tokens = tokens or os.environ.get(tokens_env) return tuple(tokens.split(':')) if tokens is not None else None
def setUp(self): diff --git a/tests/paraminfo_tests.py b/tests/paraminfo_tests.py index b34691f..92f257b 100644 --- a/tests/paraminfo_tests.py +++ b/tests/paraminfo_tests.py @@ -95,9 +95,9 @@
mw_ver = self.site.mw_version
- if mw_ver.version >= (1, 27): - if mw_ver >= '1.27.0-wmf.4' or mw_ver.suffix == 'alpha': - known.append('categorize') + if mw_ver.version >= (1, 27) \ + and (mw_ver >= '1.27.0-wmf.4' or mw_ver.suffix == 'alpha'): + known.append('categorize')
self._check_param_values(self.site, 'query+watchlist', 'type', known)
pywikibot-commits@lists.wikimedia.org