From ca73faaa757e90e5a825a57af7fd4361b3f83bea Mon Sep 17 00:00:00 2001 From: banteg <4562643+banteg@users.noreply.github.com> Date: Tue, 9 Apr 2024 02:48:34 +0400 Subject: [PATCH] fix: relax validation for timestamp and uri --- tokenlists/typing.py | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/tokenlists/typing.py b/tokenlists/typing.py index 57eb828..087a927 100644 --- a/tokenlists/typing.py +++ b/tokenlists/typing.py @@ -1,7 +1,6 @@ from itertools import chain -from typing import Any, Dict, List, Optional +from typing import Any, Dict, List, Optional, Union -from pydantic import AnyUrl from pydantic import BaseModel as _BaseModel from pydantic import ConfigDict, PastDatetime, field_validator @@ -39,16 +38,6 @@ class TokenInfo(BaseModel): tags: Optional[List[TagId]] = None extensions: Optional[Dict[str, Any]] = None - @field_validator("logoURI") - def validate_uri(cls, v: Optional[str]) -> Optional[str]: - if v is None: - return v - - if "://" not in v or not AnyUrl(v): - raise ValueError(f"'{v}' is not a valid URI") - - return v - @field_validator("extensions", mode="before") def parse_extensions(cls, v: Optional[Dict[str, Any]]) -> Optional[Dict[str, Any]]: # 1. Check extension depth first @@ -150,7 +139,7 @@ def __str__(self) -> str: class TokenList(BaseModel): name: str - timestamp: PastDatetime + timestamp: Union[PastDatetime, str] version: TokenListVersion tokens: List[TokenInfo] keywords: Optional[List[str]] = None @@ -177,22 +166,3 @@ def __init__(self, *args, **kwargs): ) model_config = ConfigDict(frozen=False) - - @field_validator("logoURI") - def validate_uri(cls, v: Optional[str]) -> Optional[str]: - if v is None: - return v - - if "://" not in v or not AnyUrl(v): - raise ValueError(f"'{v}' is not a valid URI") - - return v - - def model_dump(self, *args, **kwargs) -> Dict: - data = super().model_dump(*args, **kwargs) - - if kwargs.get("mode", "").lower() == "json": - # NOTE: This was the easiest way to make sure this property returns isoformat - data["timestamp"] = self.timestamp.isoformat() - - return data