FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix typing for data parsing by kafai-lam · Pull Request #27 · fastapi/sqlmodel · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 5 additions & 4 deletions sqlmodel/main.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
from .sql.sqltypes import GUID, AutoString

_T = TypeVar("_T")
_Model = TypeVar("_Model", bound="SQLModel")


def __dataclass_transform__(
Expand Down Expand Up @@ -520,7 +521,7 @@ def __setattr__(self, name: str, value: Any) -> None:
super().__setattr__(name, value)

@classmethod
def from_orm(cls: Type["SQLModel"], obj: Any, update: Dict[str, Any] = None):
def from_orm(cls: Type["_Model"], obj: Any, update: Dict[str, Any] = None) -> "_Model":
# Duplicated from Pydantic
if not cls.__config__.orm_mode:
raise ConfigError(
Expand Down Expand Up @@ -554,8 +555,8 @@ def from_orm(cls: Type["SQLModel"], obj: Any, update: Dict[str, Any] = None):

@classmethod
def parse_obj(
cls: Type["SQLModel"], obj: Any, update: Dict[str, Any] = None
) -> "SQLModel":
cls: Type["_Model"], obj: Any, update: Dict[str, Any] = None
) -> "_Model":
obj = cls._enforce_dict_if_root(obj)
# SQLModel, support update dict
if update is not None:
Expand All @@ -569,7 +570,7 @@ def __repr_args__(self) -> Sequence[Tuple[Optional[str], Any]]:

# From Pydantic, override to enforce validation with dict
@classmethod
def validate(cls: Type["SQLModel"], value: Any) -> "SQLModel":
def validate(cls: Type["_Model"], value: Any) -> "_Model":
if isinstance(value, cls):
return value.copy() if cls.__config__.copy_on_model_validation else value

Expand Down

Back | FazBrowse Home | New Git URL