How to use the dacite.types.extract_generic function in dacite

To help you get started, we’ve selected a few dacite 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 konradhalas / dacite / tests / test_types.py View on Github external
def test_extract_generic():
    assert extract_generic(List[int]) == (int,)
github konradhalas / dacite / dacite / core.py View on Github external
def _build_value_for_union(union: Type, data: Any, config: Config) -> Any:
    types = extract_generic(union)
    if is_optional(union) and len(types) == 2:
        return _build_value(type_=types[0], data=data, config=config)
    for inner_type in types:
        try:
            value = _build_value(type_=inner_type, data=data, config=config)
            if is_instance(value, inner_type):
                return value
        except DaciteError:
            pass
    if not config.check_types:
        return data
    raise UnionMatchError(field_type=union, value=data)
github konradhalas / dacite / dacite / core.py View on Github external
def _build_value_for_collection(collection: Type, data: Any, config: Config) -> Any:
    if is_instance(data, Mapping):
        return data.__class__(
            (key, _build_value(type_=extract_generic(collection)[1], data=value, config=config))
            for key, value in data.items()
        )
    return data.__class__(_build_value(type_=extract_generic(collection)[0], data=item, config=config) for item in data)
github konradhalas / dacite / dacite / core.py View on Github external
def _build_value_for_collection(collection: Type, data: Any, config: Config) -> Any:
    if is_instance(data, Mapping):
        return data.__class__(
            (key, _build_value(type_=extract_generic(collection)[1], data=value, config=config))
            for key, value in data.items()
        )
    return data.__class__(_build_value(type_=extract_generic(collection)[0], data=item, config=config) for item in data)