This adds support for keyword-only parameters in Structs, via a
`kw_only` configuration option. This option has the same semantics and
behavior as the `kw_only` parameter for dataclasses. If true, all
parameters specified on the respective class (*not* base classes) are
keyword-only.
This commit also changes the field-ordering algorithm used by msgspec to
match the behavior of dataclasses. This is a *breaking change*, but
helps maintain compatibility with the larger Python ecosystem (it also
makes `pyright` type check fields with the proper order).
The main way this breaking change may affect users is by causing struct
definitions with required parameters defined after optional ones to fail
at import time.
For example, the following definition is now invalid and will error at
import time.
```python
class MyStruct(Struct):
x: int = 1 # an optional parameter
y: int # a required parameter
```
To resolve this issue, you can either:
- reorder the fields so `x` is after `y`
- add a default value to `y`
- Specify `kw_only=True` in the struct definition. Keyword-only fields
may mix required and optional fields in any order, but impose
limitations on the caller.
It is unfortunate that a breaking change was needed here, but the
compatibility with `dataclasses` (and `pyright`) feels worth it. Better
break things now than later.