diff --git a/pyproject.toml b/pyproject.toml index a633e48..785a9e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "blitz-models" -version = "1.2.6" +version = "1.2.7" authors = [{ name = "Jylpah", email = "jylpah@gmail.com" }] description = "Pydantic models for Wargaming's World of Tanks Blitz game " readme = "README.md" diff --git a/src/blitzmodels/wg_api.py b/src/blitzmodels/wg_api.py index b450e85..6f40c13 100644 --- a/src/blitzmodels/wg_api.py +++ b/src/blitzmodels/wg_api.py @@ -441,15 +441,32 @@ class WGApiWoTBlitzAccountInfo(WGApiWoTBlitz): frozen=False, validate_assignment=True, populate_by_name=True ) + def __len__(self) -> int: + res: int = 0 + if self.data is not None: + for v in self.data.values(): + if v is not None: + res += 1 + return res + class WGApiWoTBlitzTankStats(WGApiWoTBlitz): """Model for WG API /wotb/tanks/stats/""" data: Dict[str, Optional[list[TankStat]]] | None = Field(default=None, alias="d") + model_config = ConfigDict( frozen=False, validate_assignment=True, populate_by_name=True ) + def __len__(self) -> int: + if self.data is not None: + for v in self.data.values(): + if v is not None: + return len(v) + break + return 0 + class PlayerAchievements(JSONExportable): """Placeholder class for data.achievements that are not collected""" @@ -622,6 +639,11 @@ def validate_data( res = {key: value for key, value in v.items() if value is not None} return res + def __len__(self) -> int: + if self.data is not None: + return len(self.data) + return 0 + def get_max_series(self) -> list[PlayerAchievementsMaxSeries]: res: list[PlayerAchievementsMaxSeries] = list() try: diff --git a/src/blitzmodels/wotinspector/wi_apiv2.py b/src/blitzmodels/wotinspector/wi_apiv2.py index 21c9cd5..43fa392 100644 --- a/src/blitzmodels/wotinspector/wi_apiv2.py +++ b/src/blitzmodels/wotinspector/wi_apiv2.py @@ -214,7 +214,7 @@ def validate_none(cls, value: str | None) -> str: else: return value - @field_validator("team", "time_alive", mode="before") + @field_validator("team", "time_alive", "death_reason", mode="before") @classmethod def validate_none_minus1(cls, value: str | None) -> str: if value is None: