diff --git a/docs/index.html b/docs/index.html index 43845e4..19dfe2f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -95,8 +95,59 @@
var K
Type variable for keys.
var T
Type variable for values.
var Ignored
A function argument that is ignored.
Type
and special forms like All
, Union
, etc.
var CheckFn
Function signature that checks if a value is of a type.
var Checks
Type of internal mapping of types to check functions.
var CastFn
Function signature that maps a value to a type.
var Casts
Type of internal mapping of types to cast functions.
-def is_type(value: Any, kind: TypeForm[Any], checks: Optional[Checks] = None) ‑> bool
+def is_type(value: Any, kind: TypeForm[Any], checks: Optional[Checks] = None) ‑> bool
Return True
if value
is of a type compatible with kind
.
-def to_type(value: Any, kind: TypeForm[T], checks: Optional[Checks] = None, casts: Optional[Casts] = None) ‑> ~T
+def to_type(value: Any, kind: TypeForm[T], checks: Optional[Checks] = None, casts: Optional[Casts] = None) ‑> ~T
Try to cast value
to the type of kind
.
-def get_origin_type(given: TypeForm[T]) ‑> Type[~T]
-
Returns the given
type, its origin, or type(obj)
.
See: typing.get_origin
def get_origin_type(given: TypeForm[T]) -> Type[T]:
- """Returns the `given` type, its origin, or `type(obj)`.
-
- See: [typing.get_origin](https://docs.python.org/3/library/typing.html#typing.get_origin)
- """
- origin = get_origin(given) or given
- if isinstance(origin, type):
- return cast(Type[T], origin) # cast due to mypy
- return cast(Type[T], type(given)) # cast due to mypy
-
-def setattrs(obj: object, **values: Dict[str, Any]) ‑> object
-
Like setattr()
but for multiple values and returns the object.
def setattrs(obj: object, **values: Dict[str, Any]) -> object:
- """Like `setattr()` but for multiple values and returns the object."""
- for name, val in values.items():
- setattr(obj, name, val)
- return obj
-
def checks_type(*types: Any) ‑> Callable[[Callable[[Any, Union[Type[Any], Any]], bool]], Callable[[Any, Union[Type[Any], Any]], bool]]
-def casts_to(*types: Any) ‑> Callable[[~T], ~T]
+def casts_to(*types: Any) ‑> Callable[[~T], ~T]
Define a type-caster for one or more types.
+def get_origin_type(given: TypeForm[T]) ‑> Type[~T]
+
Returns the given
type, its origin, or type(obj)
.
See: typing.get_origin
def get_origin_type(given: TypeForm[T]) -> Type[T]:
+ """Returns the `given` type, its origin, or `type(obj)`.
+
+ See: [typing.get_origin](https://docs.python.org/3/library/typing.html#typing.get_origin)
+ """
+ origin = get_origin(given) or given
+ if isinstance(origin, type):
+ return cast(Type[T], origin) # cast due to mypy
+ return cast(Type[T], type(given)) # cast due to mypy
+
+def setattrs(obj: object, **values: Dict[str, Any]) ‑> object
+
Like setattr()
but for multiple values and returns the object.
def setattrs(obj: object, **values: Dict[str, Any]) -> object:
+ """Like `setattr()` but for multiple values and returns the object."""
+ for name, val in values.items():
+ setattr(obj, name, val)
+ return obj
+
def is_any() ‑> bool
-def to_any(value: T) ‑> ~T
+def to_any(value: T) ‑> ~T
Always return value
.
-def is_literal(value: Any, kind: TypeForm[T]) ‑> bool
+def is_literal(value: Any, kind: TypeForm[T]) ‑> bool
Return True
if value
is a valid Literal
.
-def to_literal(value: T, kind: TypeForm[T]) ‑> ~T
+def to_literal(value: T, kind: TypeForm[T]) ‑> ~T
Return value
if it is one of the Literal
values.
-def is_union(value: Any, kind: TypeForm[T]) ‑> bool
+def is_union(value: Any, kind: TypeForm[T]) ‑> bool
Return True
if value
is a valid Union
.
-def to_union(value: Any, kind: TypeForm[T]) ‑> ~T
+def to_union(value: Any, kind: TypeForm[T]) ‑> ~T
-def is_list(value: Any, kind: TypeForm[T]) ‑> bool
+def is_list(value: Any, kind: TypeForm[T]) ‑> bool
Return True
if value
is a valid list
.
-def to_list(value: Any, kind: TypeForm[List[T]] = builtins.list) ‑> List[~T]
+def to_list(value: Any, kind: TypeForm[List[T]] = builtins.list) ‑> List[~T]
Cast value
into list
.
-def is_set(value: Any, kind: TypeForm[T]) ‑> bool
+def is_set(value: Any, kind: TypeForm[T]) ‑> bool
Return True
if value
is a valid set
.
-def to_set(value: Any, kind: TypeForm[Set[T]] = builtins.set) ‑> Set[~T]
+def to_set(value: Any, kind: TypeForm[Set[T]] = builtins.set) ‑> Set[~T]
Cast value
into set
.
-def is_dict(value: Any, kind: TypeForm[T]) ‑> bool
+def is_dict(value: Any, kind: TypeForm[T]) ‑> bool
Return True
if value
is a valid dict
.
-def to_dict(value: Any, kind: TypeForm[Dict[K, T]] = builtins.dict) ‑> Dict[~K, ~T]
+def to_dict(value: Any, kind: TypeForm[Dict[K, T]] = builtins.dict) ‑> Dict[~K, ~T]
Cast value
into a dict
.
-def is_tuple(value: Any, kind: TypeForm[T]) ‑> bool
+def is_tuple(value: Any, kind: TypeForm[T]) ‑> bool
Return True
if value
is a valid tuple
.
+class NoneType
+(...)
+