jcrist · GitHub

added 2 commits

February 4, 2023 19:24
This is a new module of struct-focused utilities. Since `replace` is a
less commonly used API we move it from the top-level namespace to
`msgspec.structs`. This isn't a breaking change since it hasn't been
released yet.
These utility functions are useful for converting a struct to a dict or
tuple. They're similar to `to_builtins` except they don't convert or
recurse. They're equivalent to the following user code, except faster:
```python
def asdict(x):
    return {n: getattr(x, n) for n in x.__struct_values__}
def astuple(x):
    return tuple(getattr(x, n) for n in x.__struct_values__)
```

@jcrist

@jcrist

@jcrist

Read the original on github.com ↗