Skip to content

Support omitting Struct attributes from encoding/decoding #199

Description

@jcrist

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions