feat(field): add get_fields method
This commit is contained in:
parent
52d1505839
commit
d640f21107
1 changed files with 12 additions and 2 deletions
|
|
@ -36,14 +36,24 @@ class Field[T: Any](ABC, PrivProperty[T]):
|
||||||
@classmethod
|
@classmethod
|
||||||
def custom[R](
|
def custom[R](
|
||||||
cls: type[Field[Any]],
|
cls: type[Field[Any]],
|
||||||
serialize: Callable[[R], str],
|
serialize: Callable[[Field[R], R], bytes],
|
||||||
deserialize: Callable[[str], R],
|
deserialize: Callable[[Field[R], bytes], R],
|
||||||
) -> type[Field[R]]:
|
) -> type[Field[R]]:
|
||||||
return inherit(
|
return inherit(
|
||||||
cls, {"serialize": serialize, "deserialize": deserialize}
|
cls, {"serialize": serialize, "deserialize": deserialize}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@final
|
||||||
|
@staticmethod
|
||||||
|
def get_fields(class_: type[Any] | Any, /) -> dict[str, Field[Any]]:
|
||||||
|
if not isinstance(class_, type):
|
||||||
|
class_ = class_.__class__
|
||||||
|
return {
|
||||||
|
k: v for k, v in class_.__dict__.items() if isinstance(v, Field)
|
||||||
|
}
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
||||||
|
@final
|
||||||
@classmethod
|
@classmethod
|
||||||
def type(cls) -> type[T]: ...
|
def type(cls) -> type[T]: ...
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue