Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
style: fix code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
trumully committed Dec 5, 2024
1 parent 794b7d5 commit 46a01b2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
19 changes: 11 additions & 8 deletions artipy/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

from __future__ import annotations

from copy import deepcopy
import random
from collections.abc import Callable
from copy import deepcopy
from itertools import starmap

from artipy import MAX_RARITY, UPGRADE_STEP
Expand Down Expand Up @@ -34,16 +34,19 @@ def _level_up_artifact(artifact: Artifact) -> None:
artifact.level = new_level
artifact.mainstat.set_value_by_level(new_level)


def pick_stat(artifact: Artifact) -> SubStat:
if not artifact.rarity:
raise ValueError("Artifact must have a rarity set")

msg = "Artifact must have a rarity set"
raise ValueError(msg)

stats = frozenset(s.name for s in (artifact.mainstat, *artifact.substats))
pool = {s: w for s, w in substat_weights.items() if s not in stats}

if not pool:
raise ValueError("No valid stats available to pick from")

msg = "No valid stats available to pick from"
raise ValueError(msg)

population, weights = map(tuple, zip(*pool.items(), strict=False))
new_stat_name = choose(population, weights)
return create_substat(name=new_stat_name, rarity=artifact.rarity)
Expand Down Expand Up @@ -385,11 +388,11 @@ def with_rarity(self, rarity: int) -> ArtifactBuilder:

self._artifact.rarity = rarity
return self

@classmethod
def five_star(cls) -> ArtifactBuilder:
return cls().with_rarity(5)

@classmethod
def four_star(cls) -> ArtifactBuilder:
return cls().with_rarity(4)
Expand Down
7 changes: 4 additions & 3 deletions artipy/data_gen.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Module that handles JSON data for the stats module."""

import orjson
import re
from collections.abc import Iterator, Mapping, MutableMapping, Sequence
from types import SimpleNamespace
from typing import Any, ClassVar, cast

import orjson

from artipy import __data__


Expand Down Expand Up @@ -36,7 +37,7 @@ def recursive_namespace(data: Any) -> Any | SimpleNamespace:
Any | SimpleNamespace: The converted data.
"""
if isinstance(data, Mapping):
data = cast(Mapping[str, Any], data)
data = cast("Mapping[str, Any]", data)
return SimpleNamespace(**{
camel_to_snake_case(k): recursive_namespace(v) for k, v in data.items()
})
Expand Down Expand Up @@ -86,7 +87,7 @@ def _load_data(self, file_name: str) -> None:
with (__data__ / file_name).open("rb") as f:
data = orjson.loads(f.read())
if not hasattr(self, "_data"):
self._data = [recursive_namespace(item) for item in data] # type: ignore
self._data = [recursive_namespace(item) for item in data] # type: ignore[reportUninitializedInstanceVariable]

def as_list(self) -> list[SimpleNamespace]:
"""Return the data as a list.
Expand Down
1 change: 1 addition & 0 deletions artipy/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def set_value_by_level(self, level: int) -> None:
"""Set the value of the mainstat based on the level of the artifact."""
self.value = possible_mainstat_values(self.name, self.rarity)[level]


@dataclass(slots=True)
class SubStat(Stat):
"""Substat dataclass for a Genshin Impact artifact."""
Expand Down
4 changes: 2 additions & 2 deletions artipy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def possible_mainstat_values(stat: StatType, rarity: int) -> list[Decimal]:
list[Decimal]: The possible values for the mainstat.
"""
mainstat_data = MAINSTAT_DATA.as_list()
values = cast(list[StatContainer], mainstat_data[1:])
values = cast("list[StatContainer]", mainstat_data[1:])
data = [
j.value
for i in values
Expand All @@ -77,7 +77,7 @@ def possible_substat_values(stat: StatType, rarity: int) -> list[Decimal]:
Returns:
list[Decimal]: The possible values for the substat.
"""
substat_data = cast(list[StatData], SUBSTAT_DATA.as_list())
substat_data = cast("list[StatData]", SUBSTAT_DATA.as_list())
data = [
d
for d in substat_data
Expand Down

0 comments on commit 46a01b2

Please sign in to comment.