How to use the typish.ClsFunction function in typish

To help you get started, we’ve selected a few typish examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ramonhagenaars / nptyping / nptyping / functions / _get_type.py View on Github external
def get_type(obj: Any) -> Type['NPType']:
    """
    Return the nptyping type of the given obj. The given obj can be a numpy
    ndarray, a dtype or a Python type. If no corresponding nptyping type
    can be determined, a TypeError is raised.
    :param obj: the object for which an nptyping type is to be returned.
    :return: a subclass of NPType.
    """
    return ClsFunction(_delegates)(obj)
github ramonhagenaars / nptyping / nptyping / _ndarray_meta.py View on Github external
def _after_subscription(cls, item: Any) -> None:
        method = ClsFunction(OrderedDict([
            (_Size, cls._only_size),
            (_Type, cls._only_type),
            (_NSizes, lambda _: ...),
            (_SizeAndType, cls._size_and_type),
            (_Sizes, cls._only_sizes),
            (_SizesAndType, cls._sizes_and_type),
            (_NSizesAndType, cls._sizes_and_type),
            (_Default, lambda _: ...),
        ]))

        if not method.understands(item):
            raise TypeError('Invalid parameter for NDArray: "{}"'.format(item))
        return method(item)
github ramonhagenaars / nptyping / nptyping / functions / _py_type.py View on Github external
Return the Python equivalent type of a numpy type. Throw a KeyError if no
    match is found for the given type. If the given np_type is not a type, it
    is attempted to create a numpy.dtype for it. Any error that is raised
    during this, is also raised by this function.

    Example:

    >>> py_type(np.int32)
    

    :param np_type: a numpy type (dtype).
    :return: a Python builtin type.
    """
    np_type = (np.dtype(np_type) if not isinstance(np_type, np.dtype)
               else np_type)
    function = ClsFunction({
        np.dtype: lambda x: _TYPE_PER_KIND[x.kind],
        type: lambda x: py_type(np.dtype(x)),
    })
    return function(np_type)