How to use the monkeytype.typing.shrink_types function in MonkeyType

To help you get started, we’ve selected a few MonkeyType 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 Instagram / MonkeyType / tests / test_typing.py View on Github external
def test_shrink_types_mixed_dicts(self, types, expected_type):
        assert shrink_types(types) == expected_type
github Instagram / MonkeyType / monkeytype / stubs.py View on Github external
def shrink_traced_types(traces: Iterable[CallTrace]) -> Tuple[Dict[str, type], Optional[type], Optional[type]]:
    """Merges the traced types and returns the minimally equivalent types"""
    arg_types: DefaultDict[str, Set[type]] = collections.defaultdict(set)
    return_types: Set[type] = set()
    yield_types: Set[type] = set()
    for t in traces:
        for arg, typ in t.arg_types.items():
            arg_types[arg].add(typ)
        if t.return_type is not None:
            return_types.add(t.return_type)
        if t.yield_type is not None:
            yield_types.add(t.yield_type)
    shrunken_arg_types = {name: shrink_types(ts) for name, ts in arg_types.items()}
    return_type = shrink_types(return_types) if return_types else None
    yield_type = shrink_types(yield_types) if yield_types else None
    return (shrunken_arg_types, return_type, yield_type)
github Instagram / MonkeyType / monkeytype / stubs.py View on Github external
def shrink_traced_types(traces: Iterable[CallTrace]) -> Tuple[Dict[str, type], Optional[type], Optional[type]]:
    """Merges the traced types and returns the minimally equivalent types"""
    arg_types: DefaultDict[str, Set[type]] = collections.defaultdict(set)
    return_types: Set[type] = set()
    yield_types: Set[type] = set()
    for t in traces:
        for arg, typ in t.arg_types.items():
            arg_types[arg].add(typ)
        if t.return_type is not None:
            return_types.add(t.return_type)
        if t.yield_type is not None:
            yield_types.add(t.yield_type)
    shrunken_arg_types = {name: shrink_types(ts) for name, ts in arg_types.items()}
    return_type = shrink_types(return_types) if return_types else None
    yield_type = shrink_types(yield_types) if yield_types else None
    return (shrunken_arg_types, return_type, yield_type)
github Instagram / MonkeyType / monkeytype / stubs.py View on Github external
def shrink_traced_types(traces: Iterable[CallTrace]) -> Tuple[Dict[str, type], Optional[type], Optional[type]]:
    """Merges the traced types and returns the minimally equivalent types"""
    arg_types: DefaultDict[str, Set[type]] = collections.defaultdict(set)
    return_types: Set[type] = set()
    yield_types: Set[type] = set()
    for t in traces:
        for arg, typ in t.arg_types.items():
            arg_types[arg].add(typ)
        if t.return_type is not None:
            return_types.add(t.return_type)
        if t.yield_type is not None:
            yield_types.add(t.yield_type)
    shrunken_arg_types = {name: shrink_types(ts) for name, ts in arg_types.items()}
    return_type = shrink_types(return_types) if return_types else None
    yield_type = shrink_types(yield_types) if yield_types else None
    return (shrunken_arg_types, return_type, yield_type)