Since Struct types force users to declare all Struct attributes, there's currently no way to hold extra state on a Struct without having it also be encoded/decoded.
Two ways to handle this:
- Add
omit=True to Meta annotations. This could also be packaged up as a parametrized type, so users could write
class Point(Struct):
x: int
y: int
_private: Omit[some_type]
- Excluded attributes with a leading underscore by default? I'm not sure if we should support this one, it may be confusing behavior. As a reference point, golang's
json doesn't encode/decode private struct attributes by default.
Since
Structtypes force users to declare allStructattributes, there's currently no way to hold extra state on aStructwithout having it also be encoded/decoded.Two ways to handle this:
omit=TruetoMetaannotations. This could also be packaged up as a parametrized type, so users could writejsondoesn't encode/decode private struct attributes by default.