It is somewhat unexpected (without thorough analysis of the docs) to see that the following:
import msgspec
class Base(msgspec.Struct, kw_only=True):
...
class Parent(Base):
a: str | None = None
b: str
Throws an error:
class Parent(Base):
E TypeError: Required field 'b' cannot follow optional fields. Either reorder the struct fields, or set `kw_only=True` in the struct definition.
Not that it is major issue, but given that kw_only and rename are part of class constructor (as well as all StructConfig fields) the expectation is/was that they will also be carried along (inherited by subclasses).
And apparently rename is getting inherited by the subclasses of Base (unlike the kw_only field), despite the fact that it is not part of StructConfig.
So would it make sense to make both fields part of StructConfig and therefore be explicit about their inheritance behaviour like other StructConfig fields?
Description
Thank you for this library.
It is somewhat unexpected (without thorough analysis of the docs) to see that the following:
Throws an error:
Not that it is major issue, but given that
kw_only
andrename
are part of class constructor (as well as allStructConfig
fields) the expectation is/was that they will also be carried along (inherited by subclasses).And apparently
rename
is getting inherited by the subclasses ofBase
(unlike thekw_only
field), despite the fact that it is not part of StructConfig.So would it make sense to make both fields part of
StructConfig
and therefore be explicit about their inheritance behaviour like otherStructConfig
fields?