from typing import Sequence
import dataclasses


def astuple(obj, *, tuple_factory=tuple) -> Sequence:
    """Return the fields of a dataclass instance as a new tuple of field values.

    If given, 'tuple_factory' will be used instead of built-in tuple.
    The function applies recursively to field values that are
    dataclass instances. This will also look into built-in containers:
    tuples, lists, and dicts.
    """
    return dataclasses.astuple(obj, tuple_factory=tuple_factory)