Skip to content

Commit

Permalink
Minor simplification of nested ifs (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
lokal-profil authored May 11, 2017
1 parent d71fb96 commit 39b4e06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 2 additions & 0 deletions tests/test_WikidataStuff.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def test_listify_string(self):

class BaseTest(unittest.TestCase):

"""Base test setting loading offline data and setting up patchers."""

def setUp(self):
"""Setup test."""
self.repo = pywikibot.Site('test', 'wikidata')
Expand Down
31 changes: 15 additions & 16 deletions wikidataStuff/WikidataStuff.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,18 @@ def addLabelOrAlias(self, lang, name, item, summary=None,
pywikibot.output(edit_summary)
elif name != item.labels[lang]:
# look at aliases
if not caseSensitive:
if name.lower() == item.labels[lang].lower():
return None
if not caseSensitive and \
(name.lower() == item.labels[lang].lower()):
return None
edit_summary %= 'alias'
if not item.aliases or lang not in item.aliases:
aliases = {lang: [name, ]}
item.editAliases(aliases, summary=edit_summary)
pywikibot.output(edit_summary)
elif name not in item.aliases[lang]:
if not caseSensitive:
if name.lower() in list_to_lower(item.aliases[lang]):
return None
if not caseSensitive and \
(name.lower() in list_to_lower(item.aliases[lang])):
return None
aliases = {lang: item.aliases[lang]}
aliases[lang].append(name)
item.editAliases(aliases, summary=edit_summary)
Expand Down Expand Up @@ -350,13 +350,12 @@ def hasQualifier(self, qual, claim):
@param claim: Claim to check
@type claim: pywikibot.Claim
"""
if claim.qualifiers:
if qual.prop in claim.qualifiers:
for s in claim.qualifiers[qual.prop]:
if self.bypassRedirect(s.getTarget()) == qual.itis:
return True
# else:
# pywikibot.output(s.getTarget())
if claim.qualifiers and qual.prop in claim.qualifiers:
for s in claim.qualifiers[qual.prop]:
if self.bypassRedirect(s.getTarget()) == qual.itis:
return True
# else:
# pywikibot.output(s.getTarget())
return False

def addQualifier(self, item, claim, qual, summary=None):
Expand Down Expand Up @@ -621,9 +620,9 @@ def compareWbTimeClaim(self, target, itis):
if itis.precision >= PRECISION['minute']:
if itis.minute != target.minute:
return False
if itis.precision >= PRECISION['second']:
if itis.second != target.second:
return False
if itis.precision >= PRECISION['second'] and \
itis.second != target.second:
return False
return True

def QtoItemPage(self, Q):
Expand Down

0 comments on commit 39b4e06

Please sign in to comment.