How to use the multimethod.get_type function in multimethod

To help you get started, we’ve selected a few multimethod 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 coady / multimethod / tests / test_methods.py View on Github external
assert issubclass(int, subtype(Union[int, float]))
    assert issubclass(Union[float, int], subtype(Union[int, float]))
    assert issubclass(List[bool], subtype(List[int]))
    assert not issubclass(Tuple[int], subtype(Tuple[int, float]))
    assert issubclass(Iterable[bool], subtype(Iterable[int]))
    assert issubclass(subtype(Iterable[int]), subtype(Iterable))
    assert issubclass(subtype(List[int]), subtype(Iterable))

    assert get_type(0) is int
    assert not isinstance(get_type(iter('')), subtype)
    assert get_type(()) is tuple
    assert get_type((0, 0.0)) == subtype(tuple, int, float)
    assert get_type([]) is list
    assert get_type([0, 0.0]) == subtype(list, int)
    assert get_type({}) is dict
    assert get_type({' ': 0}) == subtype(dict, str, int)
github coady / multimethod / tests / test_methods.py View on Github external
def test_subtype():
    assert len({subtype(List[int]), subtype(List[int])}) == 1
    assert len({subtype(List[bool]), subtype(List[int])}) == 2
    assert issubclass(int, subtype(Union[int, float]))
    assert issubclass(Union[float, int], subtype(Union[int, float]))
    assert issubclass(List[bool], subtype(List[int]))
    assert not issubclass(Tuple[int], subtype(Tuple[int, float]))
    assert issubclass(Iterable[bool], subtype(Iterable[int]))
    assert issubclass(subtype(Iterable[int]), subtype(Iterable))
    assert issubclass(subtype(List[int]), subtype(Iterable))

    assert get_type(0) is int
    assert not isinstance(get_type(iter('')), subtype)
    assert get_type(()) is tuple
    assert get_type((0, 0.0)) == subtype(tuple, int, float)
    assert get_type([]) is list
    assert get_type([0, 0.0]) == subtype(list, int)
    assert get_type({}) is dict
    assert get_type({' ': 0}) == subtype(dict, str, int)
github coady / multimethod / tests / test_methods.py View on Github external
def test_subtype():
    assert len({subtype(List[int]), subtype(List[int])}) == 1
    assert len({subtype(List[bool]), subtype(List[int])}) == 2
    assert issubclass(int, subtype(Union[int, float]))
    assert issubclass(Union[float, int], subtype(Union[int, float]))
    assert issubclass(List[bool], subtype(List[int]))
    assert not issubclass(Tuple[int], subtype(Tuple[int, float]))
    assert issubclass(Iterable[bool], subtype(Iterable[int]))
    assert issubclass(subtype(Iterable[int]), subtype(Iterable))
    assert issubclass(subtype(List[int]), subtype(Iterable))

    assert get_type(0) is int
    assert not isinstance(get_type(iter('')), subtype)
    assert get_type(()) is tuple
    assert get_type((0, 0.0)) == subtype(tuple, int, float)
    assert get_type([]) is list
    assert get_type([0, 0.0]) == subtype(list, int)
    assert get_type({}) is dict
    assert get_type({' ': 0}) == subtype(dict, str, int)
github coady / multimethod / tests / test_methods.py View on Github external
def test_subtype():
    assert len({subtype(List[int]), subtype(List[int])}) == 1
    assert len({subtype(List[bool]), subtype(List[int])}) == 2
    assert issubclass(int, subtype(Union[int, float]))
    assert issubclass(Union[float, int], subtype(Union[int, float]))
    assert issubclass(List[bool], subtype(List[int]))
    assert not issubclass(Tuple[int], subtype(Tuple[int, float]))
    assert issubclass(Iterable[bool], subtype(Iterable[int]))
    assert issubclass(subtype(Iterable[int]), subtype(Iterable))
    assert issubclass(subtype(List[int]), subtype(Iterable))

    assert get_type(0) is int
    assert not isinstance(get_type(iter('')), subtype)
    assert get_type(()) is tuple
    assert get_type((0, 0.0)) == subtype(tuple, int, float)
    assert get_type([]) is list
    assert get_type([0, 0.0]) == subtype(list, int)
    assert get_type({}) is dict
    assert get_type({' ': 0}) == subtype(dict, str, int)