Skip to content

Commit 07b941e

Browse files
committed
Fix various flake8 errors
1 parent 40a53b3 commit 07b941e

16 files changed

+58
-57
lines changed

build-scripts/get_all_mods.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def print_modlist(modlist, master_list):
5656
for info in glob.glob('data/mods/*/modinfo.json'):
5757
mod_info = json.load(open(info, encoding='utf-8'))
5858
for e in mod_info:
59-
if(e["type"] == "MOD_INFO" and
59+
if (e["type"] == "MOD_INFO" and
6060
("obsolete" not in e or not e["obsolete"])):
6161
ident = e["id"]
6262
all_mod_dependencies[ident] = e.get("dependencies", [])
@@ -72,7 +72,7 @@ def print_modlist(modlist, master_list):
7272
info_path = os.path.join(r, 'modinfo.json')
7373
mod_info = json.load(open(info_path, encoding='utf-8'))
7474
for e in mod_info:
75-
if(e["type"] == "MOD_INFO" and
75+
if (e["type"] == "MOD_INFO" and
7676
("obsolete" not in e or not e["obsolete"])):
7777
ident = e["id"]
7878
if ident == "":

lang/strip_line_numbers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def strip_pot_file(filename):
1919
except IOError as read_exc:
2020
print(read_exc)
2121
sys.exit(1)
22-
assert(len(to_write) > 1) # Wrong .pot file
22+
assert len(to_write) > 1 # Wrong .pot file
2323

2424
to_write = strip_line_numbers(to_write)
2525
to_write = strip_repeated_comments(to_write)

tools/json_tools/cddatags.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818

1919

2020
def cdda_style_json(v):
21-
if type(v) == str:
21+
if type(v) is str:
2222
return json.dumps(v)
23-
elif type(v) == list:
23+
elif type(v) is list:
2424
return f'[ {", ".join(cdda_style_json(e) for e in v)} ]'
2525
else:
2626
raise RuntimeError('Unexpected type')
@@ -53,9 +53,9 @@ def main(args):
5353
def add_definition(id_key, id, full_id, relative_path):
5454
if not id:
5555
return
56-
if type(id) == str:
56+
if type(id) is str:
5757
definitions.append((id_key, id, full_id, relative_path))
58-
elif type(id) == list:
58+
elif type(id) is list:
5959
for i in id:
6060
add_definition(id_key, i, full_id, relative_path)
6161

@@ -73,9 +73,9 @@ def add_definition(id_key, id, full_id, relative_path):
7373
"Problem reading file %s, reason: %s" %
7474
(filename, err))
7575
continue
76-
if type(json_data) == dict:
76+
if type(json_data) is dict:
7777
json_data = [json_data]
78-
elif type(json_data) != list:
78+
elif type(json_data) is not list:
7979
sys.stderr.write(
8080
"Problem parsing data from file %s, reason: "
8181
"expected a list." % filename)

tools/json_tools/convert_armor.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def get_armor_data(jo):
154154
# This will be done again in the recursive function
155155
# But we do it here for an early return on no data
156156
read_armor_data(jo, dat)
157-
if("armor" not in jo and
157+
if ("armor" not in jo and
158158
(len(dat) == 0 or (len(dat) == 1 and "material" in dat))):
159159
return dict()
160160

@@ -274,7 +274,7 @@ def gen_new(path):
274274

275275
for key in transferred_keys:
276276
if key != "material" and key in jo:
277-
del(jo[key])
277+
del jo[key]
278278

279279
return json_data if change else None
280280

tools/json_tools/extend_itemgroups.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def gen_new(path):
5353
if key not in jo:
5454
continue
5555
jo["extend"][key] = jo[key]
56-
del(jo[key])
56+
del jo[key]
5757

5858
return json_data if change else None
5959

tools/json_tools/keys.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
import sys
1515
import json
1616
import argparse
17-
from util import import_data, key_counter, ui_counts_to_columns,\
18-
WhereAction
17+
from util import import_data, key_counter, ui_counts_to_columns, WhereAction
1918

2019
parser = argparse.ArgumentParser(
2120
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)

tools/json_tools/lister.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
sys.exit(1)
5151

5252
# We'll either get a dict or a list...
53-
if type(json_data) == dict:
53+
if type(json_data) is dict:
5454
# ... and just make it a list.
5555
json_data = [json_data]
5656

tools/json_tools/monfaction_array-ify.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ def gen_new(path):
1414
with open(path, "r", encoding="utf-8") as json_file:
1515
json_data = json.load(json_file)
1616
for jo in json_data:
17-
if (type(jo) == dict and "type" in jo and
17+
if (type(jo) is dict and "type" in jo and
1818
jo["type"] == "MONSTER_FACTION"):
19-
if "by_mood" in jo and type(jo["by_mood"]) == str:
19+
if "by_mood" in jo and type(jo["by_mood"]) is str:
2020
jo["by_mood"] = [jo.pop("by_mood")]
2121
change = True
22-
if "neutral" in jo and type(jo["neutral"]) == str:
22+
if "neutral" in jo and type(jo["neutral"]) is str:
2323
jo["neutral"] = [jo.pop("neutral")]
2424
change = True
25-
if "friendly" in jo and type(jo["friendly"]) == str:
25+
if "friendly" in jo and type(jo["friendly"]) is str:
2626
jo["friendly"] = [jo.pop("friendly")]
2727
change = True
28-
if "hate" in jo and type(jo["hate"]) == str:
28+
if "hate" in jo and type(jo["hate"]) is str:
2929
jo["hate"] = [jo.pop("hate")]
3030
change = True
3131

tools/json_tools/name_strings_to_objects.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def gen_new(path):
2828
continue
2929
if not jo.get('name'):
3030
continue
31-
if type(jo['name']) == dict:
31+
if type(jo['name']) is dict:
3232
continue
3333
if jo.get('type') not in ['AMMO', 'ARMOR', 'BATTERY', 'bionic',
3434
'BIONIC_ITEM', 'BIONIC_ITEM', 'BOOK',

tools/json_tools/update-translate-dialogue-mod.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def main():
7171
for f in files:
7272
dialogues = []
7373
with open(input_dir + f, encoding="utf-8") as fp:
74-
print(f"Reading from {input_dir+f}")
74+
print(f"Reading from {input_dir + f}")
7575
json_data = json.load(fp)
7676

7777
for obj in json_data:
@@ -82,7 +82,7 @@ def main():
8282

8383
if dialogues:
8484
with open(output_dir + f, "w", encoding="utf-8") as fp:
85-
print(f" Writing to {output_dir+f}")
85+
print(f" Writing to {output_dir + f}")
8686
json.dump(dialogues, fp, ensure_ascii=False, indent=" ")
8787

8888

tools/json_tools/util.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def import_data(json_dir=JSON_DIR, json_fmatch=JSON_FNMATCH):
3939
errors.append(
4040
"Problem reading file {},".format(json_file) +
4141
" reason: {}".format(err))
42-
if type(candidates) != list:
43-
if type(candidates) == OrderedDict:
42+
if type(candidates) is not list:
43+
if type(candidates) is OrderedDict:
4444
data.append(candidates)
4545
else:
4646
errors.append(
@@ -56,13 +56,13 @@ def match_primitive_values(item_value, where_value):
5656
"""Perform any odd logic on item matching.
5757
"""
5858
# Matching interpolation for keyboard constrained input.
59-
if type(item_value) == str:
59+
if type(item_value) is str:
6060
# Direct match
6161
return bool(re.match(where_value, item_value))
62-
elif type(item_value) == int or type(item_value) == float:
62+
elif type(item_value) is int or type(item_value) is float:
6363
# match after string conversion
6464
return bool(re.match(where_value, str(item_value)))
65-
elif type(item_value) == bool:
65+
elif type(item_value) is bool:
6666
# help conversion to JSON booleans from the commandline
6767
return bool(re.match(where_value, str(item_value).lower()))
6868
else:
@@ -86,14 +86,14 @@ def matches_where(item, where_key, where_value):
8686
# So we have some value.
8787
item_value = item[where_key]
8888
# Matching interpolation for keyboard constrained input.
89-
if type(item_value) == list:
89+
if type(item_value) is list:
9090
# 1 level deep.
9191
for next_level in item_value:
9292
if match_primitive_values(next_level, where_value):
9393
return True
9494
# else...
9595
return False
96-
elif type(item_value) == dict:
96+
elif type(item_value) is dict:
9797
# Match against the keys of the dictionary... I question my logic.
9898
# 1 level deep.
9999
for next_level in item_value:
@@ -179,14 +179,14 @@ def key_counter(data, where_fn_list):
179179

180180
val = item[key]
181181
# If value is an object, tally key.subkey for all object subkeys
182-
if type(val) == OrderedDict:
182+
if type(val) is OrderedDict:
183183
for subkey in val.keys():
184184
if not subkey.startswith('//'):
185185
stats[key + '.' + subkey] += 1
186186

187187
# If value is a list of objects, tally key.subkey for each
188-
elif type(val) == list:
189-
if all(type(e) == OrderedDict for e in val):
188+
elif type(val) is list:
189+
if all(type(e) is OrderedDict for e in val):
190190
for obj in val:
191191
for subkey in obj.keys():
192192
if not subkey.startswith('//'):
@@ -208,13 +208,13 @@ def item_value_counter(_value):
208208
if isinstance(_value, str):
209209
stats[_value] += 1
210210
# Cast numbers to strings
211-
elif type(_value) == int or type(_value) == float:
211+
elif type(_value) is int or type(_value) is float:
212212
stats[str(_value)] += 1
213213
# Pull all values from objects
214-
elif type(_value) == OrderedDict:
214+
elif type(_value) is OrderedDict:
215215
stats += list_value_counter(list(_value.values()))
216216
# Pull values from list of objects or strings
217-
elif type(_value) == list:
217+
elif type(_value) is list:
218218
stats += list_value_counter(_value)
219219
else:
220220
raise ValueError("Value '%s' has unknown type %s" %
@@ -267,14 +267,14 @@ def value_counter(data, search_key, where_fn_list):
267267

268268
# If this value is a list of objects, pull parent_key.child_key
269269
# values from all of them to include in stats
270-
if type(parent_val) == list and all(type(e) == OrderedDict
270+
if type(parent_val) is list and all(type(e) is OrderedDict
271271
for e in parent_val):
272272
for od in parent_val:
273273
if child_key in od:
274274
stat_vals.append(od[child_key])
275275

276276
# If this value is a single object, get value at parent_key.child_key
277-
elif type(parent_val) == OrderedDict and child_key in parent_val:
277+
elif type(parent_val) is OrderedDict and child_key in parent_val:
278278
stat_vals.append(parent_val[child_key])
279279

280280
# Other kinds of data cannot be indexed by parent_key.child_key
@@ -381,7 +381,7 @@ def dumps(self):
381381
while items:
382382
k, v = items.pop(0)
383383
# Special cases first.
384-
if (k == "tools" or k == "components") and type(v) == list:
384+
if (k == "tools" or k == "components") and type(v) is list:
385385
self.list_of_lists(k, v)
386386
else:
387387
self.write_primitive_key_val(k, v)

tools/json_tools/values.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import argparse
66
import sys
77
import json
8-
from util import import_data, value_counter, ui_counts_to_columns,\
9-
WhereAction
8+
from util import import_data, value_counter, ui_counts_to_columns, WhereAction
109

1110
parser = argparse.ArgumentParser(description="""Count the number of
1211
times a specific values occurs for a specific key. The key may be a

tools/map_coords.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,10 @@ def info_folder(format: str) -> None:
8181
min_cx, max_cx = cx * 32, cx * 32 + 31
8282
min_cy, max_cy = cy * 32, cy * 32 + 31
8383

84-
o1 = f"{min_cx//180} {min_cy//180}"
85-
o2 = f"{min_cx//180} {max_cy//180}"
86-
o3 = f"{max_cx//180} {min_cy//180}"
87-
o4 = f"{max_cx//180} {max_cy//180}"
84+
o1 = f"{min_cx // 180} {min_cy // 180}"
85+
o2 = f"{min_cx // 180} {max_cy // 180}"
86+
o3 = f"{max_cx // 180} {min_cy // 180}"
87+
o4 = f"{max_cx // 180} {max_cy // 180}"
8888
ol = [o1]
8989
if o2 not in ol:
9090
ol.append(o2)
@@ -122,7 +122,7 @@ def info_range(r1: tuple, r2: tuple) -> None:
122122
for z in lvz:
123123
for y in lvy:
124124
for x in lvx:
125-
print(f"{x//32}.{y//32}.{z}/{x}.{y}.{z}.map", end=" ")
125+
print(f"{x // 32}.{y // 32}.{z}/{x}.{y}.{z}.map", end=" ")
126126
print("")
127127

128128

@@ -234,10 +234,10 @@ def info_range(r1: tuple, r2: tuple) -> None:
234234
cx, cy, cz = retInfo
235235

236236
print(
237-
f" Map: {cx//180}'{cx - 180 * (cx//180)}"
238-
f" {cy//180}'{cy- 180 * (cy//180)} {cz}"
237+
f" Map: {cx // 180}'{cx - 180 * (cx // 180)}"
238+
f" {cy // 180}'{cy - 180 * (cy // 180)} {cz}"
239239
)
240240

241-
print(f" File: {cx//32}.{cy//32}.{cz}/{cx}.{cy}.{cz}.map")
241+
print(f" File: {cx // 32}.{cy // 32}.{cz}/{cx}.{cy}.{cz}.map")
242242

243-
info_folder(f"{cx//32}.{cy//32}.{cz}")
243+
info_folder(f"{cx // 32}.{cy // 32}.{cz}")

tools/tileset_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def save_maps(self) -> None:
329329
row = int(_map.split('.')[0])
330330
column = int(_map.split('.')[1])
331331
folder = pathlib.Path.joinpath(self.maps_folder,
332-
f'{row//32}.{column//32}.0')
332+
f'{row // 32}.{column // 32}.0')
333333
if not self.dry_run:
334334
folder.mkdir(parents=True, exist_ok=True)
335335

tools/windows_limit_memory.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,8 @@ def __getattr__(self, item: str):
298298

299299
@staticmethod
300300
def create_buffer(obj: Any, max_buffer_len: Optional[int] = None) -> str:
301-
"""Creates a ctypes unicode buffer given an object convertible to string.
301+
"""Creates a ctypes unicode buffer given an object convertible to
302+
string.
302303
303304
Args:
304305
obj: The object from which to create a buffer. Must be convertible
@@ -407,7 +408,8 @@ def _create_io_completion_port(self) -> HANDLE:
407408

408409
def _query_information_job_object(self, structure: ctypes.Structure,
409410
query_type: int) -> ctypes.Structure:
410-
"""[Internal] Retrieves limit and job state information from the job object.
411+
"""[Internal] Retrieves limit and job state information from the job
412+
object.
411413
412414
Args:
413415
structure: The limit or job state information.
@@ -599,7 +601,8 @@ def get_process(self, pid: int) -> None:
599601
self._handle_process = handle_process
600602

601603
def limit_process_memory(self, memory_limit: int) -> None:
602-
"""Effectively limit the process memory that the target process can allocates.
604+
"""Effectively limit the process memory that the target process can
605+
allocates.
603606
604607
Args:
605608
memory_limit: The memory limit of the process, in MiB (MebiBytes).

utilities/make_iso.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def tile_convert(otile, main_id, new_tile_number):
8181
for g in ('fg', 'bg'):
8282
if g not in otile:
8383
continue
84-
if type(otile[g]) == int:
84+
if type(otile[g]) is int:
8585
if otile[g] == -1:
8686
continue
8787
otile[g] = list([otile[g]])
@@ -162,9 +162,9 @@ def tile_convert(otile, main_id, new_tile_number):
162162
for tile in ntile[g]:
163163
# if tile_num is a dict with "weight" and "sprite",
164164
# take the "sprite" number
165-
if type(tile) == dict and "sprite" in tile:
165+
if type(tile) is dict and "sprite" in tile:
166166
iso_ize(tile["sprite"])
167-
elif type(tile) == int:
167+
elif type(tile) is int:
168168
iso_ize(tile)
169169
else:
170170
raise RuntimeError("Unexpected sprite number: %s" % tile)

0 commit comments

Comments
 (0)