Skip to content

Commit

Permalink
Compare to None using identity is operator
Browse files Browse the repository at this point in the history
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
  • Loading branch information
janisozaur authored and Vultraz committed Oct 31, 2018
1 parent e3cf617 commit 9d333bc
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 29 deletions.
10 changes: 5 additions & 5 deletions data/tools/scoutDefault.py
Expand Up @@ -36,7 +36,7 @@

def applySearch(text, RE, groupId):
data = RE.search(text, 0)
if data != None:
if data is not None:
return data.group(groupId)
else:
return ""
Expand Down Expand Up @@ -65,7 +65,7 @@ def __init__(self):
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
Expand All @@ -89,9 +89,9 @@ def __init__(self):
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())
Expand Down Expand Up @@ -145,7 +145,7 @@ def __init__(self):
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()
Expand Down
2 changes: 1 addition & 1 deletion data/tools/unit_tree/animations.py
Expand Up @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion data/tools/wesnoth/campaignserver_client.py
Expand Up @@ -57,7 +57,7 @@ def __init__(self, address = None, quiet=False):
self.verbose = False
self.quiet = quiet

if address != None:
if address is not None:
self.canceled = False
self.error = False
s = address.split(":")
Expand Down
6 changes: 3 additions & 3 deletions data/tools/wesnoth/libgithub.py
Expand Up @@ -519,7 +519,7 @@ def _github_api_request(self, url, data=None, method=None, authenticate=False):
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
Expand All @@ -541,7 +541,7 @@ def _execute(self, command, cwd=None, check_error=False):
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()

Expand Down Expand Up @@ -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)
16 changes: 8 additions & 8 deletions data/tools/wesnoth/wescamp.py
Expand Up @@ -449,13 +449,13 @@ def assert_wescamp(configured):
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
Expand All @@ -464,7 +464,7 @@ def assert_wescamp(configured):

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)
Expand Down Expand Up @@ -520,10 +520,10 @@ def assert_wescamp(configured):
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)

Expand All @@ -546,7 +546,7 @@ def assert_wescamp(configured):
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)

Expand Down Expand Up @@ -581,7 +581,7 @@ def assert_wescamp(configured):
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)

Expand Down
6 changes: 3 additions & 3 deletions data/tools/wesnoth/wmldata.py
Expand Up @@ -275,7 +275,7 @@ def make_string(self, indent = 0, textdomain = ""):

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)
Expand Down Expand Up @@ -577,11 +577,11 @@ def get_quantity(self, tag, difficulty, default = None):
"""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

Expand Down
6 changes: 3 additions & 3 deletions data/tools/wesnoth/wmlparser.py
Expand Up @@ -378,12 +378,12 @@ def parse_macro(self):
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]:
Expand Down Expand Up @@ -675,7 +675,7 @@ def parse_top(self, data, state = None):
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(
Expand Down
2 changes: 1 addition & 1 deletion data/tools/wesnoth/wmlparser3.py
Expand Up @@ -309,7 +309,7 @@ def __init__(self, wesnoth_exe = None, config_dir = None,
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

Expand Down
2 changes: 1 addition & 1 deletion utils/gdb/register_wesnoth_pretty_printers.py
Expand Up @@ -43,7 +43,7 @@ def wesnoth_lookup_function(val):
# Get the type name.
typename = type.tag

if typename == None:
if typename is None:
return None

# Iterate over local dictionary of types to determine
Expand Down
2 changes: 1 addition & 1 deletion utils/simulate_lobby_traffic.py
Expand Up @@ -50,7 +50,7 @@ def is_in_path(filename):
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)

Expand Down
4 changes: 2 additions & 2 deletions utils/wiki_grabber.py
Expand Up @@ -121,7 +121,7 @@ def get_value(data, key):

res = re.compile("^" + key + " *= *(.*)$", re.M).search(data)

if res != None:
if res is not None:
res = res.group(1)

return res
Expand All @@ -131,7 +131,7 @@ def process_header(data):

page = get_value(data, "@page")
order = get_value(data, "@order")
if order == None:
if order is None:
order = 10000

return [page, order]
Expand Down

0 comments on commit 9d333bc

Please sign in to comment.