Skip to content

Commit

Permalink
add more type hints and isort. (#1613)
Browse files Browse the repository at this point in the history
* add more type hints and isort.

* Revert "add more type hints and isort."

This reverts commit b0f4615.

* type hints
  • Loading branch information
Killklli authored Sep 17, 2023
1 parent 070cf13 commit d2d78d4
Show file tree
Hide file tree
Showing 52 changed files with 326 additions and 229 deletions.
9 changes: 5 additions & 4 deletions cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@
import codecs
import json
import os
import time
import random
import sys
import time
import traceback
import zipfile
import boto3
from io import BytesIO
import traceback

import boto3

from randomizer.Enums.Settings import SettingsMap
from randomizer.Fill import Generate_Spoiler
from randomizer.Patching.Patcher import load_base_rom
from randomizer.Settings import Settings
from randomizer.SettingStrings import decrypt_settings_string_enum
from randomizer.Spoiler import Spoiler
from randomizer.Patching.Patcher import load_base_rom

load_base_rom()
dynamodb = boto3.resource("dynamodb", aws_access_key_id=os.environ.get("AWS_ID"), aws_secret_access_key=os.environ.get("AWS_KEY"), region_name="us-west-2")
Expand Down
8 changes: 4 additions & 4 deletions generate_rando_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ async def initialize():
# Module of Lists used for list_selector macros
from randomizer.Enums.Types import ItemRandoSelector, KeySelector
from randomizer.Lists.EnemyTypes import EnemySelector
from randomizer.Lists.Item import HHItemSelector, CustomStartingMoveSelector
from randomizer.Lists.HardMode import HardSelector
from randomizer.Lists.Item import CustomStartingMoveSelector, HHItemSelector
from randomizer.Lists.Logic import GlitchSelector
from randomizer.Lists.Minigame import MinigameSelector
from randomizer.Lists.Plandomizer import PlandomizerPanels, PlannableItems, PlannableMinigames, PlannableSpawns
from randomizer.Lists.QoL import QoLSelector
from randomizer.Lists.HardMode import HardSelector
from randomizer.Lists.Warps import VanillaBananaportSelector
from randomizer.Lists.Songs import ExcludedSongsSelector
from randomizer.Lists.Warps import VanillaBananaportSelector
from randomizer.Lists.WrinklyHints import PointSpreadSelector

# Module of lists and utils used for plandomizer
from randomizer.PlandoUtils import PlandoItemFilter, PlandoMinigameFilter, PlandoOptionClassAnnotation, PlandoShopSortFilter
from randomizer.Lists.Plandomizer import PlandomizerPanels, PlannableItems, PlannableMinigames, PlannableSpawns

js.listeners = []
js.progression_presets = []
Expand Down
1 change: 1 addition & 0 deletions js.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""This is a dummy module that only exists to override the built in pyodide module."""
import json
from typing import TYPE_CHECKING


def postMessage(message: str) -> None:
Expand Down
35 changes: 22 additions & 13 deletions randomizer/CompileHints.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Compile a list of hints based on the settings."""

import json
import random
import randomizer.ItemPool as ItemPool
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, Tuple, Union

import randomizer.ItemPool as ItemPool
from randomizer.Enums.Events import Events
from randomizer.Enums.HintType import HintType
from randomizer.Enums.Items import Items
Expand All @@ -18,7 +20,12 @@
from randomizer.Lists.ShufflableExit import ShufflableExits
from randomizer.Lists.WrinklyHints import ClearHintMessages, hints
from randomizer.Patching.UpdateHints import UpdateHint
from randomizer.Spoiler import Spoiler

if TYPE_CHECKING:
from randomizer.Enums.Transitions import Transitions
from randomizer.Lists.WrinklyHints import HintLocation
from randomizer.LogicClasses import Region
from randomizer.Spoiler import Spoiler


class Hint:
Expand All @@ -38,7 +45,7 @@ def __init__(
subtype="joke",
joke=False,
joke_defined=False,
):
) -> None:
"""Create wrinkly hint text object."""
self.kongs = kongs.copy()
self.hint = hint
Expand Down Expand Up @@ -74,7 +81,7 @@ def downgrade(self):
class MoveInfo:
"""Move Info for Wrinkly hint text."""

def __init__(self, *, name="", kong="", move_type="", move_level=0, important=False):
def __init__(self, *, name="", kong="", move_type="", move_level=0, important=False) -> None:
"""Create move info object."""
self.name = name
self.kong = kong
Expand Down Expand Up @@ -408,7 +415,7 @@ def toJSON(self):
globally_hinted_location_ids = []


def compileHints(spoiler: Spoiler):
def compileHints(spoiler: Spoiler) -> bool:
"""Create a hint distribution, generate buff hints, and place them in locations."""
ClearHintMessages()
hint_distribution = hint_distribution_default.copy()
Expand Down Expand Up @@ -1803,7 +1810,7 @@ def compileHints(spoiler: Spoiler):
return True


def getRandomHintLocation(location_list=None, kongs=None, levels=None, move_name=None):
def getRandomHintLocation(location_list: None = None, kongs: None = None, levels: None = None, move_name: None = None) -> HintLocation:
"""Return an unoccupied hint location. The parameters can be used to specify location requirements."""
valid_unoccupied_hint_locations = [
hint
Expand All @@ -1825,7 +1832,7 @@ def getRandomHintLocation(location_list=None, kongs=None, levels=None, move_name
return None


def getHintLocationsForAccessibleHintItems(hint_item_ids):
def getHintLocationsForAccessibleHintItems(hint_item_ids: Union[Set[Items], List[Items]]) -> List[Union[HintLocation, Any]]:
"""Given a list of hint item ids, return unoccupied HintLocation objects they correspond to, possibly returning an empty list."""
accessible_hints = []
for item_id in hint_item_ids:
Expand All @@ -1852,7 +1859,7 @@ def resetHintList():
hint.priority = hint.original_priority


def compileMicrohints(spoiler: Spoiler):
def compileMicrohints(spoiler: Spoiler) -> None:
"""Create guaranteed level + kong hints for various items."""
spoiler.microhints = {}
if spoiler.settings.microhints_enabled != MicrohintsEnabled.off:
Expand Down Expand Up @@ -2033,7 +2040,7 @@ def PointValueOfItem(settings, item_id):
return 0


def TryCreatingLoadingZoneHint(spoiler: Spoiler, transition, disallowedRegions: list = None):
def TryCreatingLoadingZoneHint(spoiler: Spoiler, transition: Transitions, disallowedRegions: Optional[List[Regions]] = None) -> str:
"""Try to create a hint message for the given transition. If this hint is determined to be bad, it will return false and not place the hint."""
if disallowedRegions is None:
disallowedRegions = []
Expand Down Expand Up @@ -2066,13 +2073,13 @@ def TryCreatingLoadingZoneHint(spoiler: Spoiler, transition, disallowedRegions:
return f"If you're looking for \x04{destinationName}\x04, follow the path \x08from {entranceName}\x08."


def UpdateSpoilerHintList(spoiler: Spoiler):
def UpdateSpoilerHintList(spoiler: Spoiler) -> None:
"""Write hints to spoiler object."""
for hint in hints:
spoiler.hint_list[hint.name] = hint.hint


def GetRegionOfLocation(spoiler, location_id):
def GetRegionOfLocation(spoiler: Spoiler, location_id: Locations) -> Region:
"""Given the id of a Location, return the Region it belongs to."""
location = spoiler.LocationList[location_id]
# Shop locations are tied to the level, not the shop regions
Expand All @@ -2088,7 +2095,9 @@ def GetRegionOfLocation(spoiler, location_id):
raise Exception("Unable to find Region for Location") # This should never trigger!


def GenerateMultipathDict(spoiler, useless_locations):
def GenerateMultipathDict(
spoiler: Spoiler, useless_locations: Dict[Union[Items, Kongs], List[Any]]
) -> Tuple[Dict[Union[Locations, int], str], Dict[Union[Locations, int], List[Union[Locations, int]]]]:
"""Create multipath hint text and identify relevant goal locations for each eligible woth location.
Returns two dicts.
Expand Down Expand Up @@ -2153,7 +2162,7 @@ def GenerateMultipathDict(spoiler, useless_locations):
return multipath_dict_hints, multipath_dict_goals


def join_words(words):
def join_words(words: List[str]) -> str:
"""Join a list of words with an 'and' for grammatical perfection."""
if len(words) > 2:
return "%s, and %s" % (", ".join(words[:-1]), words[-1])
Expand Down
3 changes: 2 additions & 1 deletion randomizer/Enums/Kongs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Kong enum."""

from enum import IntEnum, auto
from typing import List
from typing import TYPE_CHECKING, List


class Kongs(IntEnum):
Expand Down
4 changes: 3 additions & 1 deletion randomizer/Enums/Settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""File containing enums to represent all settings."""

from enum import IntEnum, auto
from typing import TYPE_CHECKING

from randomizer.Enums.Items import Items
from randomizer.Lists.EnemyTypes import Enemies
Expand Down Expand Up @@ -1038,7 +1040,7 @@ class SettingsStringDataType(IntEnum):
SettingsStringIntRangeMap = {}


def addSettingIntRange(settingEnum, maxVal, minVal=0):
def addSettingIntRange(settingEnum: SettingsStringEnum, maxVal: int, minVal: int = 0) -> None:
"""Add an entry to the SettingsStringIntRangeMap."""
SettingsStringIntRangeMap[settingEnum] = {"max": maxVal, "min": minVal}

Expand Down
Loading

0 comments on commit d2d78d4

Please sign in to comment.