From 4ebcda692e0a571f12422bd4886b4ee62d6cb86b Mon Sep 17 00:00:00 2001 From: massimilianodelliubaldini <8584296+massimilianodelliubaldini@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:06:17 -0500 Subject: [PATCH] More type hint updates. --- worlds/jakanddaxter/Client.py | 12 ++++++------ worlds/jakanddaxter/__init__.py | 8 ++++---- worlds/jakanddaxter/client/MemoryReader.py | 4 ++-- worlds/jakanddaxter/client/ReplClient.py | 10 +++++----- worlds/jakanddaxter/regs/RegionBase.py | 15 ++++++++------- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/worlds/jakanddaxter/Client.py b/worlds/jakanddaxter/Client.py index b2faacd6a1..9b2198d72b 100644 --- a/worlds/jakanddaxter/Client.py +++ b/worlds/jakanddaxter/Client.py @@ -10,7 +10,7 @@ import colorama import asyncio from asyncio import Task -from typing import Set, Awaitable, Optional +from typing import Set, Awaitable import pymem from pymem.exception import ProcessNotFound @@ -90,7 +90,7 @@ class JakAndDaxterContext(CommonContext): repl_task: asyncio.Task memr_task: asyncio.Task - def __init__(self, server_address: Optional[str], password: Optional[str]) -> None: + def __init__(self, server_address: str | None, password: str | None) -> None: self.repl = JakAndDaxterReplClient(self.on_log_error, self.on_log_warn, self.on_log_success, @@ -175,10 +175,10 @@ class JakAndDaxterContext(CommonContext): async def json_to_game_text(self, args: dict): if "type" in args and args["type"] in {"ItemSend"}: - my_item_name: Optional[str] = None - my_item_finder: Optional[str] = None - their_item_name: Optional[str] = None - their_item_owner: Optional[str] = None + my_item_name: str | None = None + my_item_finder: str | None = None + their_item_name: str | None = None + their_item_owner: str | None = None item = args["item"] recipient = args["receiving"] diff --git a/worlds/jakanddaxter/__init__.py b/worlds/jakanddaxter/__init__.py index 2548c8caa5..6717219911 100644 --- a/worlds/jakanddaxter/__init__.py +++ b/worlds/jakanddaxter/__init__.py @@ -1,4 +1,4 @@ -from typing import Any, ClassVar, Callable, Optional, Union +from typing import Any, ClassVar, Callable from math import ceil import Utils import settings @@ -66,8 +66,8 @@ class JakAndDaxterSettings(settings.Group): root_directory: RootDirectory = RootDirectory( "%programfiles%/OpenGOAL-Launcher/features/jak1/mods/JakMods/archipelagoal") - auto_detect_root_directory: Union[AutoDetectRootDirectory, bool] = True - enforce_friendly_options: Union[EnforceFriendlyOptions, bool] = True + auto_detect_root_directory: AutoDetectRootDirectory | bool = True + enforce_friendly_options: EnforceFriendlyOptions | bool = True class JakAndDaxterWebWorld(WebWorld): @@ -195,7 +195,7 @@ class JakAndDaxterWorld(World): # These functions and variables are Options-driven, keep them as instance variables here so that we don't clog up # the seed generation routines with options checking. So we set these once, and then just use them as needed. - can_trade: Callable[[CollectionState, int, Optional[int]], bool] + can_trade: Callable[[CollectionState, int, int | None], bool] orb_bundle_item_name: str = "" orb_bundle_size: int = 0 total_trade_orbs: int = 0 diff --git a/worlds/jakanddaxter/client/MemoryReader.py b/worlds/jakanddaxter/client/MemoryReader.py index c9af179fa6..92ce53c405 100644 --- a/worlds/jakanddaxter/client/MemoryReader.py +++ b/worlds/jakanddaxter/client/MemoryReader.py @@ -1,7 +1,7 @@ import logging import random import struct -from typing import ByteString, Callable, Optional +from typing import ByteString, Callable import json import pymem from pymem import pattern @@ -297,7 +297,7 @@ class JakAndDaxterMemoryReader: if not self.connected: self.log_error(logger, "The Memory Reader is not connected!") - memory_version: Optional[int] = None + memory_version: int | None = None try: memory_version = self.read_goal_address(memory_version_offset, sizeof_uint32) if memory_version == expected_memory_version: diff --git a/worlds/jakanddaxter/client/ReplClient.py b/worlds/jakanddaxter/client/ReplClient.py index 1c0f37f5b8..ab8810d70c 100644 --- a/worlds/jakanddaxter/client/ReplClient.py +++ b/worlds/jakanddaxter/client/ReplClient.py @@ -6,7 +6,7 @@ import struct import random from dataclasses import dataclass from queue import Queue -from typing import Optional, Callable +from typing import Callable import pymem from pymem.exception import ProcessNotFound, ProcessError @@ -30,10 +30,10 @@ logger = logging.getLogger("ReplClient") @dataclass class JsonMessageData: - my_item_name: Optional[str] = None - my_item_finder: Optional[str] = None - their_item_name: Optional[str] = None - their_item_owner: Optional[str] = None + my_item_name: str | None = None + my_item_finder: str | None = None + their_item_name: str | None = None + their_item_owner: str | None = None class JakAndDaxterReplClient: diff --git a/worlds/jakanddaxter/regs/RegionBase.py b/worlds/jakanddaxter/regs/RegionBase.py index e8c7da1610..1f2747e1e1 100644 --- a/worlds/jakanddaxter/regs/RegionBase.py +++ b/worlds/jakanddaxter/regs/RegionBase.py @@ -1,4 +1,4 @@ -from typing import Iterable, Callable, Optional +from typing import Iterable from BaseClasses import MultiWorld, Region from ..GameID import jak1_name from ..Locations import JakAndDaxterLocation, location_table @@ -7,6 +7,7 @@ from ..locs import (OrbLocations as Orbs, ScoutLocations as Scouts, SpecialLocations as Specials, OrbCacheLocations as Caches) +from worlds.generic.Rules import CollectionRule class JakAndDaxterRegion(Region): @@ -25,7 +26,7 @@ class JakAndDaxterRegion(Region): self.level_name = level_name self.orb_count = orb_count - def add_cell_locations(self, locations: Iterable[int], access_rule: Optional[Callable] = None): + def add_cell_locations(self, locations: Iterable[int], access_rule: CollectionRule | None = None) -> None: """ Adds a Power Cell Location to this region with the given access rule. Converts Game ID's to AP ID's for you. @@ -34,7 +35,7 @@ class JakAndDaxterRegion(Region): ap_id = Cells.to_ap_id(loc) self.add_jak_locations(ap_id, location_table[ap_id], access_rule) - def add_fly_locations(self, locations: Iterable[int], access_rule: Optional[Callable] = None): + def add_fly_locations(self, locations: Iterable[int], access_rule: CollectionRule | None = None) -> None: """ Adds a Scout Fly Location to this region with the given access rule. Converts Game ID's to AP ID's for you. @@ -43,7 +44,7 @@ class JakAndDaxterRegion(Region): ap_id = Scouts.to_ap_id(loc) self.add_jak_locations(ap_id, location_table[ap_id], access_rule) - def add_special_locations(self, locations: Iterable[int], access_rule: Optional[Callable] = None): + def add_special_locations(self, locations: Iterable[int], access_rule: CollectionRule | None = None) -> None: """ Adds a Special Location to this region with the given access rule. Converts Game ID's to AP ID's for you. @@ -54,7 +55,7 @@ class JakAndDaxterRegion(Region): ap_id = Specials.to_ap_id(loc) self.add_jak_locations(ap_id, location_table[ap_id], access_rule) - def add_cache_locations(self, locations: Iterable[int], access_rule: Optional[Callable] = None): + def add_cache_locations(self, locations: Iterable[int], access_rule: CollectionRule | None = None) -> None: """ Adds an Orb Cache Location to this region with the given access rule. Converts Game ID's to AP ID's for you. @@ -63,7 +64,7 @@ class JakAndDaxterRegion(Region): ap_id = Caches.to_ap_id(loc) self.add_jak_locations(ap_id, location_table[ap_id], access_rule) - def add_orb_locations(self, level_index: int, bundle_index: int, access_rule: Optional[Callable] = None): + def add_orb_locations(self, level_index: int, bundle_index: int, access_rule: CollectionRule | None = None) -> None: """ Adds Orb Bundle Locations to this region equal to `bundle_count`. Used only when Per-Level Orbsanity is enabled. The orb factory class will handle AP ID enumeration. @@ -77,7 +78,7 @@ class JakAndDaxterRegion(Region): location.access_rule = access_rule self.locations.append(location) - def add_jak_locations(self, ap_id: int, name: str, access_rule: Optional[Callable] = None): + def add_jak_locations(self, ap_id: int, name: str, access_rule: CollectionRule | None = None) -> None: """ Helper function to add Locations. Not to be used directly. """