pg.typing.Callable¶
Accessible via pg.typing.Callable
.
- class Callable(args=None, kw=None, returns=None, default=MISSING_VALUE, transform=None, callable_type=None, is_noneable=False, frozen=False)[source]¶
Bases:
pg.typing.Generic
,ValueSpecBase
Value spec for callable.
Examples:
# A required callable object with any args. pg.typing.Callable() # An optional callable objects with the first argument as int, and the # second argument as float. The field has None as its default value. pg.typing.Callable([pg.typing.Int(), pg.typing.Float()]).noneable() # An callable object that has its first argument as int, and has keyword # arguments 'x' (any type), 'y' (a str) and return value as int. pg.typing.Callable( [pg.typing.Int()], kw=[ ('x', pg.typing.Any()), ('y', pg.typing.Str()) ], returns=pg.typing.Int())
See also:
pg.typing.Functor
.Attributes:
Value specs for positional arguments.
Returns forward references used in this spec.
Names and value specs for keyword arguments.
Value spec for return value.
Methods:
format
(*[, markdown])Format this spec.
is_compatible
(other)Returns if current spec is compatible with the other value spec.
to_json
(**kwargs)Returns a plain Python value as a representation for this object.
- property forward_refs: Set[ForwardRef]¶
Returns forward references used in this spec.
- is_compatible(other)[source]¶
Returns if current spec is compatible with the other value spec.
- Return type:
- to_json(**kwargs)[source]¶
Returns a plain Python value as a representation for this object.
A plain Python value are basic python types that can be serialized into JSON, e.g:
bool
,int
,float
,str
,dict
(with string keys),list
,tuple
where the container types should have plain Python values as their values.