Compare to None using identity is operator

This is a trivial change that replaces `==` operator with `is` operator, following PEP 8 guideline:

> Comparisons to singletons like None should always be done with is or is not, never the equality operators.

https://legacy.python.org/dev/peps/pep-0008/#programming-recommendations
This commit is contained in:
Michał Janiszewski 2018-10-30 22:14:45 +01:00 committed by Charles Dang
parent e3cf617d8a
commit 9d333bc95a
11 changed files with 29 additions and 29 deletions

View File

@ -36,7 +36,7 @@ AI_SCOUTS_TEXT = "\n\t[ai]%s\n\t[/ai]" % SCOUTS_TEXT.replace('\n','\n\t')
def applySearch(text, RE, groupId):
data = RE.search(text, 0)
if data != None:
if data is not None:
return data.group(groupId)
else:
return ""
@ -65,7 +65,7 @@ class wikiAi:
self.updated_description = ""
def addAiData(self, aiContent):
if aiContent != None:
if aiContent is not None:
self.start = applySearch(aiContent, AI_START, 'text')
self.scouts = applySearch(aiContent, AI_SCOUTS, 'text')
self.full_description = aiContent
@ -89,9 +89,9 @@ class wikiSide:
self.scouts_setting = False
def addAiData(self, sideContent):
if sideContent != None:
if sideContent is not None:
aiDetail = ai_block.search(sideContent, 0)
while aiDetail != None:
while aiDetail is not None:
if applySearch(aiDetail.group(), AI_TIME, 'text') == "" and applySearch(aiDetail.group(), AI_TURNS, 'text') == "":
self.ai.append(wikiAi())
self.ai[self.getCurrentAiNumber()].addAiData(aiDetail.group())
@ -145,7 +145,7 @@ class wikiScenario:
def parseScenario (self, scenarioContent):
self.addScenarioData(scenarioContent)
sideDetail = side_block.search(scenarioContent, 0)
while sideDetail != None:
while sideDetail is not None:
self.addSideData(sideDetail.group())
self.addAiData(sideDetail.group())
searchStart = sideDetail.end()

View File

@ -64,7 +64,7 @@ def write_table_row(out, unit, color, name = None):
if abil.get_all(tag = "teleport"):
needed["teleport"] = True
if name == None: name = unit.id
if name is None: name = unit.id
out.write("<tr><td class=\"%s\">%s</td>" % (color and "c1" or "c2", name))

View File

@ -57,7 +57,7 @@ class CampaignClient:
self.verbose = False
self.quiet = quiet
if address != None:
if address is not None:
self.canceled = False
self.error = False
s = address.split(":")

View File

@ -519,7 +519,7 @@ class GitHub(object):
return json_parsed
def _github_have_authorization(self):
return self.authorization != None
return self.authorization is not None
def _github_authorization(self):
if self.authorization:
return self.authorization
@ -541,7 +541,7 @@ class GitHub(object):
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, cwd=cwd)
out = ""
err = ""
while(p.poll() == None):
while(p.poll() is None):
out += p.stdout.read()
err += p.stderr.read()
@ -615,6 +615,6 @@ def get_build_system(possible_dirs=[]):
Returns: The Addon object of the build-system
"""
global _g
if _g == None:
if _g is None:
_g = _gen(possible_dirs)
return next(_g)

View File

@ -449,13 +449,13 @@ if __name__ == "__main__":
logging.getLogger().addHandler(handler)
server = "localhost"
if(args.server != None):
if(args.server is not None):
server = args.server
if args.port != None:
if args.port is not None:
server += ":" + args.port
campaignd_configured = True
elif args.branch != None:
elif args.branch is not None:
for port, version in libwml.CampaignClient.portmap:
if version.startswith(args.branch):
server += ":" + port
@ -464,7 +464,7 @@ if __name__ == "__main__":
target = None
tmp = tempdir()
if(args.temp_dir != None):
if(args.temp_dir is not None):
if(args.upload_all):
logging.error("TEMP-DIR not allowed for UPLOAD-ALL.")
sys.exit(2)
@ -520,10 +520,10 @@ if __name__ == "__main__":
print(k)
# Upload an addon to wescamp.
elif(args.upload != None):
elif(args.upload is not None):
assert_campaignd(campaignd_configured)
assert_wescamp(wescamp_configured)
if(wescamp == None):
if(wescamp is None):
logging.error("No wescamp checkout specified")
sys.exit(2)
@ -546,7 +546,7 @@ if __name__ == "__main__":
elif(args.upload_all):
assert_campaignd(campaignd_configured)
assert_wescamp(wescamp_configured)
if(wescamp == None):
if(wescamp is None):
logging.error("No wescamp checkout specified.")
sys.exit(2)
@ -581,7 +581,7 @@ if __name__ == "__main__":
elif(args.checkout or args.checkout_readonly):
assert_wescamp(wescamp_configured)
if(wescamp == None):
if(wescamp is None):
logging.error("No wescamp checkout specified.")
sys.exit(2)

View File

@ -275,7 +275,7 @@ class DataSub(Data):
bytes = ""
for r in result:
if r != None:
if r is not None:
# For networking, we need actual bytestream here, not unicode.
if type(r) is unicode: r = r.encode("utf8")
bytes += str(r)
@ -577,11 +577,11 @@ class DataSub(Data):
"""For the even lazier, looks for a value inside a difficulty ifdef.
"""
v = self.get_text_val(tag)
if v != None: return v
if v is not None: return v
for ifdef in self.get_ifdefs(["EASY", "NORMAL", "HARD"][difficulty]):
v = ifdef.get_text_val(tag)
if v != None: return v
if v is not None: return v
return default

View File

@ -378,12 +378,12 @@ class Parser:
elif macro[0] == ".":
dirpath = self.current_path + macro[1:]
# Otherwise, try to interpret the macro as a filename in the data dir.
elif self.data_dir != None:
elif self.data_dir is not None:
dirpath = self.data_dir + "/" + macro
else:
dirpath = None
if dirpath != None and os.path.exists(dirpath):
if dirpath is not None and os.path.exists(dirpath):
dirpath = os.path.normpath(dirpath)
if self.only_expand_pathes:
if not [x for x in self.only_expand_pathes if os.path.commonprefix([dirpath, x]) == x]:
@ -675,7 +675,7 @@ class Parser:
self.read_while(" ")
text = self.read_lines_until("#enddef")
if text == None:
if text is None:
raise Error(self, "#define without #enddef")
self.macros[params[0]] = self.Macro(

View File

@ -309,7 +309,7 @@ class Parser:
if data_dir: self.data_dir = os.path.abspath(data_dir)
self.keep_temp_dir = None
self.temp_dir = None
self.no_preprocess = (wesnoth_exe == None)
self.no_preprocess = (wesnoth_exe is None)
self.preprocessed = None
self.verbose = False

View File

@ -43,7 +43,7 @@ def create_wesnoth_lookup_function(pretty_printers_dict):
# Get the type name.
typename = type.tag
if typename == None:
if typename is None:
return None
# Iterate over local dictionary of types to determine

View File

@ -50,7 +50,7 @@ while len(clients) > 0 and time.monotonic() < waiting_start_time + EXIT_WAIT_TIM
time.sleep(1.0)
clients_copy = list(clients)
for c in clients_copy:
if c.poll() != None:
if c.poll() is not None:
# The process has terminated, remove it from the set.
clients.remove(c)

View File

@ -121,7 +121,7 @@ if __name__ == "__main__":
res = re.compile("^" + key + " *= *(.*)$", re.M).search(data)
if res != None:
if res is not None:
res = res.group(1)
return res
@ -131,7 +131,7 @@ if __name__ == "__main__":
page = get_value(data, "@page")
order = get_value(data, "@order")
if order == None:
if order is None:
order = 10000
return [page, order]