dispatch
module fastcore.dispatch in fastcore
Classes
builtins.object
DispatchReg
TypeDispatch
DispatchReg
class DispatchReg(builtins.object)
| A global registry for `TypeDispatch` objects keyed by function name
|
| Methods defined here:
|
|
DispatchReg.__call__
|
| __call__(self, f)
| Call self as a function.
|
|
DispatchReg.__init__
|
| __init__(self)
| Initialize self. See help(type(self)) for accurate signature.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
TypeDispatch
class TypeDispatch(builtins.object)
| TypeDispatch(funcs=(), bases=())
|
| Dictionary-like object; `__getitem__` matches keys of types using `issubclass`
|
| Methods defined here:
|
|
TypeDispatch.__call__
|
| __call__(self, *args, **kwargs)
| Call self as a function.
|
|
TypeDispatch.__get__
|
| __get__(self, inst, owner)
|
|
TypeDispatch.__getitem__
|
| __getitem__(self, k)
| Find first matching type that is a super-class of `k`
|
|
TypeDispatch.__init__
|
| __init__(self, funcs=(), bases=())
| Initialize self. See help(type(self)) for accurate signature.
|
|
TypeDispatch.__repr__
|
| __repr__(self)
| Return repr(self).
|
|
TypeDispatch.add
|
| add(self, f)
| Add type `t` and function `f`
|
|
TypeDispatch.first
|
| first(self)
| Get first function in ordered dict of type:func.
|
|
TypeDispatch.returns
|
| returns(self, x)
| Get the return type of annotation of `x`.
|
| ----------------------------------------------------------------------
| Data descriptors defined here:
|
| __dict__
| dictionary for instance variables (if defined)
|
| __weakref__
| list of weak references to the object (if defined)
Functions
cast = (object,object) -> cast
default_set_meta
default_set_meta(self, x, as_copy=False)
Copy over `_meta` from `x` to `res`, if it's missing
explode_types
explode_types(o)
Return the type of `o`, potentially in nested dictionaries for thing that are listy
lenient_issubclass
lenient_issubclass(cls, types)
If possible return whether `cls` is a subclass of `types`, otherwise return False.
retain_meta
retain_meta(x, res, as_copy=False)
Call `res.set_meta(x)`, if it exists
retain_type
retain_type(new, old=None, typ=None, as_copy=False)
Cast `new` to type of `old` or `typ` if it's a superclass
retain_types
retain_types(new, old=None, typs=None)
Cast each item of `new` to type of matching item in `old` if it's a superclass
sorted_topologically
sorted_topologically(iterable, *, cmp=, reverse=False)
Return a new list containing all items from the iterable sorted topologically