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

Stardew Valley: Remove Python 3.8 backports 🎉 #3982

Merged
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
6 changes: 1 addition & 5 deletions worlds/stardew_valley/content/unpacking.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from __future__ import annotations

from graphlib import TopologicalSorter
from typing import Iterable, Mapping, Callable

from .game_content import StardewContent, ContentPack, StardewFeatures
from .vanilla.base import base_game as base_game_content_pack
from ..data.game_item import GameItem, ItemSource

try:
from graphlib import TopologicalSorter
except ImportError:
from graphlib_backport import TopologicalSorter # noqa


def unpack_content(features: StardewFeatures, packs: Iterable[ContentPack]) -> StardewContent:
# Base game is always registered first.
Expand Down
4 changes: 2 additions & 2 deletions worlds/stardew_valley/data/artisan.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from dataclasses import dataclass

from .game_item import kw_only, ItemSource
from .game_item import ItemSource


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class MachineSource(ItemSource):
item: str # this should be optional (worm bin)
machine: str
Expand Down
18 changes: 4 additions & 14 deletions worlds/stardew_valley/data/game_item.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
import enum
import sys
from abc import ABC
from dataclasses import dataclass, field
from types import MappingProxyType
from typing import List, Iterable, Set, ClassVar, Tuple, Mapping, Callable, Any

from ..stardew_rule.protocol import StardewRule

if sys.version_info >= (3, 10):
kw_only = {"kw_only": True}
else:
kw_only = {}

DEFAULT_REQUIREMENT_TAGS = MappingProxyType({})


Expand All @@ -36,21 +30,17 @@ class ItemTag(enum.Enum):
class ItemSource(ABC):
add_tags: ClassVar[Tuple[ItemTag]] = ()

other_requirements: Tuple[Requirement, ...] = field(kw_only=True, default_factory=tuple)

@property
def requirement_tags(self) -> Mapping[str, Tuple[ItemTag, ...]]:
return DEFAULT_REQUIREMENT_TAGS

# FIXME this should just be an optional field, but kw_only requires python 3.10...
@property
def other_requirements(self) -> Iterable[Requirement]:
return ()


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class GenericSource(ItemSource):
regions: Tuple[str, ...] = ()
"""No region means it's available everywhere."""
other_requirements: Tuple[Requirement, ...] = ()


@dataclass(frozen=True)
Expand All @@ -59,7 +49,7 @@ class CustomRuleSource(ItemSource):
create_rule: Callable[[Any], StardewRule]


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class CompoundSource(ItemSource):
sources: Tuple[ItemSource, ...] = ()

Expand Down
17 changes: 8 additions & 9 deletions worlds/stardew_valley/data/harvest.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
from dataclasses import dataclass
from typing import Tuple, Sequence, Mapping

from .game_item import ItemSource, kw_only, ItemTag, Requirement
from .game_item import ItemSource, ItemTag
from ..strings.season_names import Season


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class ForagingSource(ItemSource):
regions: Tuple[str, ...]
seasons: Tuple[str, ...] = Season.all
other_requirements: Tuple[Requirement, ...] = ()


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class SeasonalForagingSource(ItemSource):
season: str
days: Sequence[int]
Expand All @@ -22,17 +21,17 @@ def as_foraging_source(self) -> ForagingSource:
return ForagingSource(seasons=(self.season,), regions=self.regions)


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class FruitBatsSource(ItemSource):
...


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class MushroomCaveSource(ItemSource):
...


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class HarvestFruitTreeSource(ItemSource):
add_tags = (ItemTag.CROPSANITY,)

Expand All @@ -46,7 +45,7 @@ def requirement_tags(self) -> Mapping[str, Tuple[ItemTag, ...]]:
}


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class HarvestCropSource(ItemSource):
add_tags = (ItemTag.CROPSANITY,)

Expand All @@ -61,6 +60,6 @@ def requirement_tags(self) -> Mapping[str, Tuple[ItemTag, ...]]:
}


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class ArtifactSpotSource(ItemSource):
amount: int
13 changes: 6 additions & 7 deletions worlds/stardew_valley/data/shop.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
from dataclasses import dataclass
from typing import Tuple, Optional

from .game_item import ItemSource, kw_only, Requirement
from .game_item import ItemSource
from ..strings.season_names import Season

ItemPrice = Tuple[int, str]


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class ShopSource(ItemSource):
shop_region: str
money_price: Optional[int] = None
items_price: Optional[Tuple[ItemPrice, ...]] = None
seasons: Tuple[str, ...] = Season.all
other_requirements: Tuple[Requirement, ...] = ()

def __post_init__(self):
assert self.money_price is not None or self.items_price is not None, "At least money price or items price need to be defined."
assert self.items_price is None or all(isinstance(p, tuple) for p in self.items_price), "Items price should be a tuple."


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class MysteryBoxSource(ItemSource):
amount: int


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class ArtifactTroveSource(ItemSource):
amount: int


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class PrizeMachineSource(ItemSource):
amount: int


@dataclass(frozen=True, **kw_only)
@dataclass(frozen=True, kw_only=True)
class FishingTreasureChestSource(ItemSource):
amount: int
4 changes: 1 addition & 3 deletions worlds/stardew_valley/data/skill.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from dataclasses import dataclass, field

from ..data.game_item import kw_only


@dataclass(frozen=True)
class Skill:
name: str
has_mastery: bool = field(**kw_only)
has_mastery: bool = field(kw_only=True)
5 changes: 1 addition & 4 deletions worlds/stardew_valley/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ def __call__(self, item: Item):


def load_item_csv():
try:
from importlib.resources import files
except ImportError:
from importlib_resources import files # noqa
from importlib.resources import files

items = []
with files(data).joinpath("items.csv").open() as file:
Expand Down
5 changes: 1 addition & 4 deletions worlds/stardew_valley/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ def __call__(self, name: str, code: Optional[int], region: str) -> None:


def load_location_csv() -> List[LocationData]:
try:
from importlib.resources import files
except ImportError:
from importlib_resources import files
from importlib.resources import files

with files(data).joinpath("locations.csv").open() as file:
reader = csv.DictReader(file)
Expand Down
2 changes: 0 additions & 2 deletions worlds/stardew_valley/requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions worlds/stardew_valley/test/stability/TestStability.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@

# <function Location.<lambda> at 0x102ca98a0>
lambda_regex = re.compile(r"^<function Location\.<lambda> at (.*)>$")
# Python 3.10.2\r\n
python_version_regex = re.compile(r"^Python (\d+)\.(\d+)\.(\d+)\s*$")


class TestGenerationIsStable(SVTestCase):
Expand Down
Loading