msgspec.Structs allow empty mutable collections as default values, however Ruff currently warns about these.
Docs:
Builtin empty mutable collections ([], {}, set(), and bytearray()) may be used as default values (as in c above). Since defaults of these types are so common, these are “syntactic sugar” for specifying the corresponding default_factory (to avoid accidental sharing of mutable values). A default of [] is identical to a default of field(default_factory=list), with a new list instance used each time.
Ruff version: 0.0.292
MRE:
import msgspec
class Example(msgspec.Struct):
c: list[int] = [] # Mutable class attributes should be annotated with `typing.ClassVar` Ruff(RUF012)