Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions sqlmodel/main.py
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