jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[W0048] Merge 'if' statements

Also shorten for loop in Claim.same_as()

Change-Id: I956d564a0ac268f4bbdfeb0bc3efc4ef9d55054b
---
M pywikibot/page/_pages.py
M pywikibot/page/_wikibase.py
2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/pywikibot/page/_pages.py b/pywikibot/page/_pages.py
index 3d48204..852f0ad 100644
--- a/pywikibot/page/_pages.py
+++ b/pywikibot/page/_pages.py
@@ -1910,9 +1910,8 @@
for item in self.site.deletedrevs(self, start=timestamp,
content=content, total=1, **kwargs):
# should only be one item with one revision
- if item['title'] == self.title():
- if 'revisions' in item:
- return item['revisions'][0]
+ if item['title'] == self.title() and 'revisions' in item:
+ return item['revisions'][0]
return []

def markDeletedRevision(self, timestamp, undelete: bool = True):
@@ -2136,10 +2135,9 @@

def __init__(self, source, title: str = '', ns=0) -> None:
"""Instantiate a Page object."""
- if isinstance(source, pywikibot.site.BaseSite):
- if not title:
- raise ValueError('Title must be specified and not empty '
- 'if source is a Site.')
+ if isinstance(source, pywikibot.site.BaseSite) and not title:
+ raise ValueError('Title must be specified and not empty '
+ 'if source is a Site.')
super().__init__(source, title, ns)

@property
@@ -3129,9 +3127,9 @@
mailrequest = self.site.simple_request(**params)
maildata = mailrequest.submit()

- if 'emailuser' in maildata:
- if maildata['emailuser']['result'] == 'Success':
- return True
+ if 'emailuser' in maildata \
+ and maildata['emailuser']['result'] == 'Success':
+ return True
return False

def block(self, *args, **kwargs):
diff --git a/pywikibot/page/_wikibase.py b/pywikibot/page/_wikibase.py
index 503bee3..f90577e 100644
--- a/pywikibot/page/_wikibase.py
+++ b/pywikibot/page/_wikibase.py
@@ -1395,28 +1395,26 @@
ignore_refs: bool = True
) -> bool:
"""Check if two claims are same."""
- if ignore_rank:
- attributes = ['id', 'snaktype', 'target']
- else:
- attributes = ['id', 'snaktype', 'rank', 'target']
+ attributes = ['id', 'snaktype', 'target']
+ if not ignore_rank:
+ attributes.append('rank')
for attr in attributes:
if getattr(self, attr) != getattr(other, attr):
return False

- if not ignore_quals:
- if not self._claim_mapping_same(self.qualifiers, other.qualifiers):
- return False
+ if not (ignore_quals or self._claim_mapping_same(self.qualifiers,
+ other.qualifiers)):
+ return False

if not ignore_refs:
if len(self.sources) != len(other.sources):
return False
+
for source in self.sources:
- same = False
for other_source in other.sources:
if self._claim_mapping_same(source, other_source):
- same = True
break
- if not same:
+ else:
return False

return True

To view, visit change 772015. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I956d564a0ac268f4bbdfeb0bc3efc4ef9d55054b
Gerrit-Change-Number: 772015
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged