Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applied safe linting suggestions #2155

Open
wants to merge 1 commit into
base: Dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ASM/rom_diff.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/usr/bin/env/python3

import json
import struct
import sys

Expand Down
4 changes: 2 additions & 2 deletions CI.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def check_hell_mode_tricks(fix_errors: bool = False) -> None:

if set(presets['Hell Mode']['allowed_tricks']) == {trick['name'] for trick in logic_tricks.values()}:
if presets['Hell Mode']['allowed_tricks'] != [trick['name'] for trick in logic_tricks.values()]:
error(f'Order of logic tricks in Hell Mode preset does not match definition order in SettingsList.py', True)
error('Order of logic tricks in Hell Mode preset does not match definition order in SettingsList.py', True)

if fix_errors:
presets['Hell Mode']['allowed_tricks'] = [trick['name'] for trick in logic_tricks.values()]
Expand Down Expand Up @@ -207,7 +207,7 @@ def exit_ci(fix_errors: bool = False) -> NoReturn:
print('Run `CI.py --fix --no_unit_tests` to automatically fix these errors.', file=sys.stderr)
sys.exit(1)
else:
print(f'CI checks successful.')
print('CI checks successful.')
sys.exit(0)


Expand Down
2 changes: 1 addition & 1 deletion Dungeon.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations
from collections.abc import Iterator
from typing import TYPE_CHECKING, Optional, Any
from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
from Hints import HintArea
Expand Down
2 changes: 1 addition & 1 deletion Gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def gui_main() -> None:
def version_check(name: str, version: str, url: str) -> None:
try:
process = subprocess.Popen([shutil.which(name.lower()), "--version"], stdout=subprocess.PIPE)
except Exception as ex:
except Exception:
raise VersionError('{name} is not installed. Please install {name} {version} or later'.format(name=name, version=version), url)

while True:
Expand Down
3 changes: 1 addition & 2 deletions Hints.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
import urllib.request
from collections import OrderedDict, defaultdict
from collections.abc import Callable, Iterable
from collections.abc import Iterable
from enum import Enum
from typing import TYPE_CHECKING, Optional
from urllib.error import URLError, HTTPError
Expand All @@ -27,7 +27,6 @@
TypeAlias = str

if TYPE_CHECKING:
from Entrance import Entrance
from Goals import GoalCategory
from Location import Location
from Spoiler import Spoiler
Expand Down
2 changes: 1 addition & 1 deletion Location.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from collections.abc import Callable, Iterable
from enum import Enum
from typing import TYPE_CHECKING, Optional, Any, overload
from typing import TYPE_CHECKING, Optional, overload

from HintList import misc_item_hint_table, misc_location_hint_table
from LocationList import location_table, location_is_viewable, LocationAddress, LocationDefault, LocationFilterTags
Expand Down
4 changes: 2 additions & 2 deletions Music.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def process_sequences(rom: Rom, ids: Iterable[tuple[str, int]], seq_type: str =
lines = io.TextIOWrapper(stream).readlines() # Use TextIOWrapper in order to get text instead of binary from the seq.
# Strip newline(s)
lines = [line.rstrip() for line in lines]
except Exception as ex:
except Exception:
raise FileNotFoundError(f'Error reading meta file for: "{fname}". This should never happen')

# Create new sequence, checking third line for correct type
Expand Down Expand Up @@ -424,7 +424,7 @@ def rebuild_sequences(rom: Rom, sequences: list[Sequence], log: CosmeticsLog, sy
if new_entry.size <= 0x10:
raise Exception(f'Invalid sequence file "{seq.name}.seq"')
new_entry.data[1] = 0x20
except FileNotFoundError as ex:
except FileNotFoundError:
raise FileNotFoundError(f'No sequence file for: "{seq.name}"')
else:
new_entry.size = old_sequences[i].size
Expand Down
2 changes: 1 addition & 1 deletion N64Patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def apply_patch_file(rom: Rom, settings: Settings, sub_file: Optional[str] = Non
try:
with patch_archive.open(sub_file, 'r') as stream:
patch_data = stream.read()
except KeyError as ex:
except KeyError:
raise FileNotFoundError('Patch file missing from archive. Invalid Player ID.')
else:
with open(file, 'rb') as stream:
Expand Down
2 changes: 1 addition & 1 deletion OcarinaSongs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations
import random
import sys
from collections.abc import Callable, Sequence
from collections.abc import Sequence
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon re-reviewing, I noticed that you removed this import which is used in type aliases in lines 19 and 20. We should probably run a type checker as part of CI to catch errors like this. There may be other similar ones in this PR, haven't gone through everything yet.

from itertools import chain
from typing import TYPE_CHECKING, Optional

Expand Down
2 changes: 1 addition & 1 deletion Patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ def calculate_traded_flags(world):

# Update "Princess Ruto got the Spiritual Stone!" text before the midboss in Jabu
if reward_text is None or location is None or location.item is None:
new_message = f"\x08Princess Ruto got \x01\x05\x43nothing\x05\x40!\x01Well, that's disappointing...\x02"
new_message = "\x08Princess Ruto got \x01\x05\x43nothing\x05\x40!\x01Well, that's disappointing...\x02"
else:
reward_texts = {
'Kokiri Emerald': "the \x05\x42Kokiri Emerald\x05\x40",
Expand Down
2 changes: 1 addition & 1 deletion Region.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations
from enum import Enum, unique
from typing import TYPE_CHECKING, Optional, Any
from typing import TYPE_CHECKING, Optional

if TYPE_CHECKING:
from Dungeon import Dungeon
Expand Down
2 changes: 1 addition & 1 deletion Rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def read_rom(self, input_file: str, output_file: Optional[str] = None, verify_cr
try:
with open(input_file, 'rb') as stream:
self.buffer = bytearray(stream.read())
except FileNotFoundError as ex:
except FileNotFoundError:
raise FileNotFoundError(f'Invalid path to Base ROM: "{input_file}"')

# Validate ROM file
Expand Down
2 changes: 1 addition & 1 deletion Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def to_json(self, *, legacy_starting_items: bool = False) -> dict[str, Any]:
('_settings' in self.distribution.src_dict and setting.name in self.distribution.src_dict['_settings'].keys())
)
# Don't want to include list starting equipment and songs, these are consolidated into starting_items
and (legacy_starting_items or not (setting.name in LEGACY_STARTING_ITEM_SETTINGS))
and (legacy_starting_items or setting.name not in LEGACY_STARTING_ITEM_SETTINGS)
and (setting.name != 'starting_items' or not legacy_starting_items)
}

Expand Down
2 changes: 1 addition & 1 deletion Spoiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import random
from collections import OrderedDict
from itertools import chain
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING

from Item import Item
from LocationList import location_sort_order
Expand Down
2 changes: 1 addition & 1 deletion Unittest.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def test_fuzzer(self):
self.verify_woth(spoiler)
self.verify_playthrough(spoiler)
self.verify_disables(spoiler)
except Exception as e:
except Exception:
# output the settings file in case of any failure
with open(settings_file, 'w') as f:
d = {k: settings.settings_dict[k] for k in out_keys}
Expand Down
4 changes: 2 additions & 2 deletions World.py
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ def set_goals(self) -> None:
# one copy if the other is unreachable.
#
# Similar criteria is used for Ganon's Boss Key in plentiful keysanity.
if not 'Light Arrows' in self.item_added_hint_types['always']:
if 'Light Arrows' not in self.item_added_hint_types['always']:
if self.settings.item_pool_value == 'plentiful':
arrows = 2
else:
Expand Down Expand Up @@ -1281,7 +1281,7 @@ def update_useless_areas(self, spoiler: Spoiler) -> None:
exclude_item_list.remove(i)

for i in self.item_added_hint_types['barren']:
if not (i in exclude_item_list):
if i not in exclude_item_list:
exclude_item_list.append(i)

# The idea here is that if an item shows up in woth, then the only way
Expand Down