jenkins-bot submitted this change.

View Change

Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
[IMPR] do not compare against None but use explicit "is None"

- do not compare against None but use explicit "is None"
- also use an explicit return at end of the function
if function have already a return value other than None

Change-Id: Ifb4646b601d2370471459cc564af1b3537c303f5
---
M pywikibot/comms/threadedhttp.py
1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index 1f24e6b..b8c3e24 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -76,20 +76,17 @@
@property
def exception(self):
"""Get the exception, if any."""
- if isinstance(self.data, Exception):
- return self.data
+ return self.data if isinstance(self.data, Exception) else None

@property
def response_headers(self):
"""Return the response headers."""
- if not self.exception:
- return self.data.headers
+ return self.data.headers if not self.exception else None

@property
def raw(self):
"""Return the raw response body."""
- if not self.exception:
- return self.data.content
+ return self.data.content if not self.exception else None

@property
def parsed_uri(self):
@@ -109,8 +106,7 @@

@rtype: int
"""
- if not self.exception:
- return self.data.status_code
+ return self.data.status_code if not self.exception else None

@property
def header_encoding(self):
@@ -146,15 +142,15 @@
charset = 'latin1'
else:
charset = self.charset
+ lookup = codecs.lookup(charset) if charset else None
if (self.header_encoding
- and codecs.lookup(
- self.header_encoding) != (
- codecs.lookup(charset) if charset else None)):
+ and (lookup is None
+ or codecs.lookup(self.header_encoding) != lookup)):
if charset:
pywikibot.warning(
- 'Encoding "{0}" requested but "{1}" '
- 'received in the header.'.format(
- charset, self.header_encoding))
+ 'Encoding "{}" requested but "{}" '
+ 'received in the header.'
+ .format(charset, self.header_encoding))
try:
# TODO: Buffer decoded content, weakref does remove it too
# early (directly after this method)

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

Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ifb4646b601d2370471459cc564af1b3537c303f5
Gerrit-Change-Number: 606413
Gerrit-PatchSet: 4
Gerrit-Owner: Xqt <info@gno.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchanek97@gmail.com>
Gerrit-Reviewer: Xqt <info@gno.de>
Gerrit-Reviewer: jenkins-bot
Gerrit-MessageType: merged