Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
julien777z committed Feb 14, 2025
1 parent a79605e commit 191f959
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions bloxlink_lib/models/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from datetime import datetime
import discord
from pydantic import BaseModel, RootModel, PrivateAttr, field_validator
from typing import (
Callable,
Iterable,
Expand All @@ -20,12 +18,15 @@
WithJsonSchema,
ConfigDict,
Field,
ConfigDict,
SkipValidation,
PrivateAttr,
field_validator,
RootModel,
)
from pydantic.fields import FieldInfo
from generics import get_filled_type
import hikari
import discord

Snowflake = Annotated[int, BeforeValidator(int), WithJsonSchema({"type": "int"})]

Expand Down Expand Up @@ -72,15 +73,18 @@ def get_type(self) -> Any:
if self._generic_type_value:
return self._generic_type_value

self._generic_type_value = get_filled_type(self, BaseModel, 0)
try:
self._generic_type_value = get_filled_type(self, BaseModel, 0)
except TypeError:
pass

return self._generic_type_value


class PydanticDict[K, V](RootModel[dict[K, V]]):
"""A Pydantic model that represents a dictionary."""

root: dict[K, V] = Field(default_factory=dict)
root: Annotated[dict[K, V], Field(default_factory=dict)]

def __iter__(self):
return iter(self.root)
Expand Down Expand Up @@ -115,9 +119,6 @@ def items(self):
def update(self, other: dict[K, V]):
self.root.update(other)

def __iter__(self):
return iter(self.root)

def __len__(self) -> int:
return len(self.root)

Expand All @@ -134,7 +135,7 @@ def __repr__(self) -> str:
class PydanticList[T](RootModel[list[T]]):
"""A Pydantic model that represents a list."""

root: list[T] = Field(default_factory=list)
root: Annotated[list[T], Field(default_factory=list)]

def __iter__(self):
return iter(self.root)
Expand Down

0 comments on commit 191f959

Please sign in to comment.