Re: [dataclasses] add a NON_FIELDS sentinel after which all attributes are ignored.

On Fri, Jun 23, 2023 at 12:18 PM Eric V. Smith <eric@trueblade.com> wrote:
Can't know - not my design, it was Randolf's question. They might represent an internal state that should not be relayed on serialization or conversion, for example. I can imagine some scenarios where I'd want some instance attributes to be shorter lived and non-transient, although, I'd more likely build the class "manually" instead of a dataclass - or, more likely, put the dataclass under a wrapper layer that would handle the "perishable" states.

On 6/23/2023 11:34 AM, Joao S. O. Bueno wrote:
I think you can make dataclasses itself ignore the field by judicious use of `field` parameters. If there's some code that's looking through `dataclasses.fields` but wants to ignore some fields, irrespective of what dataclasses is doing, then I'd say it's on the caller to have a list of fields to ignore. But without knowing the use case, it's hard to say. Eric

On Fri, Jun 23, 2023 at 12:18 PM Eric V. Smith <eric@trueblade.com> wrote:
Can't know - not my design, it was Randolf's question. They might represent an internal state that should not be relayed on serialization or conversion, for example. I can imagine some scenarios where I'd want some instance attributes to be shorter lived and non-transient, although, I'd more likely build the class "manually" instead of a dataclass - or, more likely, put the dataclass under a wrapper layer that would handle the "perishable" states.

On 6/23/2023 11:34 AM, Joao S. O. Bueno wrote:
I think you can make dataclasses itself ignore the field by judicious use of `field` parameters. If there's some code that's looking through `dataclasses.fields` but wants to ignore some fields, irrespective of what dataclasses is doing, then I'd say it's on the caller to have a list of fields to ignore. But without knowing the use case, it's hard to say. Eric
participants (2)
-
Eric V. Smith
-
Joao S. O. Bueno