Skip to content

Commit

Permalink
refactor: model BaseUUIDModel for UUID handling
Browse files Browse the repository at this point in the history
  • Loading branch information
staciax committed Dec 29, 2024
1 parent af2ce47 commit c12f9e3
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 75 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ quote-annotations = true
runtime-evaluated-base-classes = [
"pydantic.BaseModel",
"valorant.models.base.BaseModel",
"valorant.models.base.BaseUUIDModel",
]

[tool.ruff.lint.flake8-unused-arguments]
Expand Down
10 changes: 5 additions & 5 deletions valorant/models/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from pydantic import Field

from ..enums import AbilitySlot
from .base import BaseModel, LocalizedField
from .base import BaseModel, BaseUUIDModel, LocalizedField

__all__ = (
'Ability',
Expand All @@ -38,8 +38,8 @@
)


class Role(BaseModel):
uuid: str
class Role(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
description: LocalizedField
display_icon: str = Field(alias='displayIcon')
Expand Down Expand Up @@ -69,8 +69,8 @@ def __repr__(self) -> str:
return f'<Ability display_name={self.display_name!r}>'


class Agent(BaseModel):
uuid: str
class Agent(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
description: LocalizedField
developer_name: str = Field(alias='developerName')
Expand Down
17 changes: 17 additions & 0 deletions valorant/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
DEALINGS IN THE SOFTWARE.
"""

from __future__ import annotations

from typing import Generic, TypeVar
from uuid import UUID

from pydantic import BaseModel as PydanticBaseModel, Field

T = TypeVar('T')

__all__ = (
'BaseModel',
'BaseUUIDModel',
'LocalizedField',
'Response',
)
Expand All @@ -42,6 +46,19 @@ def __repr__(self) -> str:
return f'<{self.__class__.__name__}>'


class BaseUUIDModel(BaseModel):
uuid: UUID = Field(alias='uuid')

def __eq__(self, other: object) -> bool:
return isinstance(other, self.__class__) and self.uuid == other.uuid

def __ne__(self, other: object) -> bool:
return not self.__eq__(other)

def __hash__(self) -> int:
return hash(self.uuid)


class LocalizedField(BaseModel):
de_DE: str = Field(alias='de-DE')
es_ES: str = Field(alias='es-ES')
Expand Down
10 changes: 5 additions & 5 deletions valorant/models/buddies.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseUUIDModel, LocalizedField

__all__ = (
'Buddy',
Expand All @@ -40,8 +40,8 @@
from .themes import Theme


class Level(BaseModel):
uuid: str
class Level(BaseUUIDModel):
# uuid: str
charm_level: int = Field(alias='charmLevel')
hide_if_not_owned: bool = Field(alias='hideIfNotOwned')
display_name: LocalizedField = Field(alias='displayName')
Expand All @@ -52,8 +52,8 @@ def __repr__(self) -> str:
return f'<Level display_name={self.display_name!r}>'


class Buddy(BaseModel):
uuid: str
class Buddy(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
is_hidden_if_not_owned: bool = Field(alias='isHiddenIfNotOwned')
theme_uuid: str | None = Field(alias='themeUuid')
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/bundles.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseUUIDModel, LocalizedField

__all__ = ('Bundle',)


class Bundle(BaseModel):
uuid: str
class Bundle(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
display_name_sub_text: Any = Field(alias='displayNameSubText')
description: LocalizedField
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/ceremonies.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseUUIDModel, LocalizedField

__all__ = ('Ceremony',)


class Ceremony(BaseModel):
uuid: str
class Ceremony(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
asset_path: str = Field(alias='assetPath')
6 changes: 3 additions & 3 deletions valorant/models/competitive_tiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pydantic import Field

from ..enums import DivisionTier
from .base import BaseModel, LocalizedField
from .base import BaseModel, BaseUUIDModel, LocalizedField

__all__ = (
'CompetitiveTier',
Expand All @@ -46,8 +46,8 @@ class Tier(BaseModel):
rank_triangle_up_icon: str | None = Field(alias='rankTriangleUpIcon')


class CompetitiveTier(BaseModel):
uuid: str
class CompetitiveTier(BaseUUIDModel):
# uuid: str
asset_object_name: str = Field(alias='assetObjectName')
tiers: list[Tier]
asset_path: str = Field(alias='assetPath')
6 changes: 3 additions & 3 deletions valorant/models/content_tiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseUUIDModel, LocalizedField

__all__ = ('ContentTier',)


class ContentTier(BaseModel):
uuid: str
class ContentTier(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
dev_name: str = Field(alias='devName')
rank: int
Expand Down
10 changes: 5 additions & 5 deletions valorant/models/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from pydantic import Field

from ..enums import RelationType, RewardType
from .base import BaseModel, LocalizedField
from .base import BaseModel, BaseUUIDModel, LocalizedField

__all__ = (
'Chapter',
Expand All @@ -57,9 +57,9 @@
log = logging.getLogger(__name__)


class Reward(BaseModel):
class Reward(BaseUUIDModel):
# uuid: str
type: RewardType
uuid: str
amount: int
is_highlighted: bool = Field(alias='isHighlighted')

Expand Down Expand Up @@ -120,8 +120,8 @@ async def fetch_relationship(self, *, client: Client) -> Agent | Event | Season
return None


class Contract(BaseModel):
uuid: str
class Contract(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
display_icon: str | None = Field(alias='displayIcon')
ship_it: bool = Field(alias='shipIt')
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/currencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseUUIDModel, LocalizedField

__all__ = ('Currency',)


class Currency(BaseModel):
uuid: str
class Currency(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
display_name_singular: LocalizedField = Field(alias='displayNameSingular')
display_icon: str = Field(alias='displayIcon')
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseUUIDModel, LocalizedField

__all__ = ('Event',)


class Event(BaseModel):
uuid: str
class Event(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
short_display_name: LocalizedField = Field(alias='shortDisplayName')
start_time: datetime = Field(alias='startTime')
Expand Down
10 changes: 5 additions & 5 deletions valorant/models/gamemodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from pydantic import Field

from ..enums import GameRule
from .base import BaseModel, LocalizedField
from .base import BaseModel, BaseUUIDModel, LocalizedField

__all__ = (
'Equippable',
Expand All @@ -53,8 +53,8 @@ class GameRuleBoolOverride(BaseModel):
state: bool


class GameMode(BaseModel):
uuid: str
class GameMode(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
description: LocalizedField | None
duration: LocalizedField | None
Expand All @@ -72,8 +72,8 @@ class GameMode(BaseModel):
asset_path: str = Field(alias='assetPath')


class Equippable(BaseModel):
uuid: str
class Equippable(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
category: str
display_icon: str = Field(alias='displayIcon')
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/gear.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseModel, BaseUUIDModel, LocalizedField

__all__ = (
'Detail',
Expand All @@ -53,8 +53,8 @@ class ShopData(BaseModel):
asset_path: str = Field(alias='assetPath')


class Gear(BaseModel):
uuid: str
class Gear(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
description: LocalizedField
descriptions: list[LocalizedField]
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/level_borders.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseUUIDModel, LocalizedField

__all__ = ('LevelBorder',)


class LevelBorder(BaseModel):
uuid: str
class LevelBorder(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
starting_level: int = Field(alias='startingLevel')
level_number_appearance: str = Field(alias='levelNumberAppearance')
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseModel, BaseUUIDModel, LocalizedField

__all__ = (
'Callout',
Expand All @@ -46,8 +46,8 @@ class Callout(BaseModel):
location: Location


class Map(BaseModel):
uuid: str
class Map(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
narrative_description: Any = Field(alias='narrativeDescription')
tactical_description: LocalizedField | None = Field(alias='tacticalDescription')
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/missions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pydantic import Field

from ..enums import MissionTag, MissionType
from .base import BaseModel, LocalizedField
from .base import BaseModel, BaseUUIDModel, LocalizedField

__all__ = (
'Mission',
Expand All @@ -38,8 +38,8 @@ class Objective(BaseModel):
value: int


class Mission(BaseModel):
uuid: str
class Mission(BaseUUIDModel):
# uuid: str
display_name: LocalizedField | None = Field(alias='displayName')
title: LocalizedField | None
type: MissionType | None
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/player_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseUUIDModel, LocalizedField

__all__ = ('PlayerCard',)

Expand All @@ -37,8 +37,8 @@
from .themes import Theme


class PlayerCard(BaseModel):
uuid: str
class PlayerCard(BaseUUIDModel):
# uuid: str
display_name: LocalizedField = Field(alias='displayName')
is_hidden_if_not_owned: bool = Field(alias='isHiddenIfNotOwned')
theme_uuid: str | None = Field(alias='themeUuid')
Expand Down
6 changes: 3 additions & 3 deletions valorant/models/player_titles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@

from pydantic import Field

from .base import BaseModel, LocalizedField
from .base import BaseUUIDModel, LocalizedField

__all__ = ('PlayerTitle',)


class PlayerTitle(BaseModel):
uuid: str
class PlayerTitle(BaseUUIDModel):
# uuid: str
display_name: LocalizedField | None = Field(alias='displayName')
title_text: LocalizedField | None = Field(alias='titleText')
is_hidden_if_not_owned: bool = Field(alias='isHiddenIfNotOwned')
Expand Down
Loading

0 comments on commit c12f9e3

Please sign in to comment.