Closed gvanrossum closed 7 years ago
I think @ncoghlan's major point here is that we should have arguments that describe how the class will be used, not how it will be implemented.
But, I don't see a lot of precedence for this in core Python types, so I think we should stick with the attrs-like description of what features you're asking for in the generated class, not how you plan to use it. For example, if you want to add your own __repr__
, you'd set repr=False
. There's a direct correspondence with parameter names and Python features. I don't think hiding Python features serves the users.
For example, what would slots=False
become? You'd need some parameter or combination of parameters that means you want to have instances where you're able to add dynamic attributes that are non-fields, and you're okay with the increased per-instance memory usage.
I think there are some features (like slots) that should be exposed directly since they're unique to Python and don't correspond with any general characteristics of data type definitions, but I do think there are others (like orderable and hashable) where a higher level formulation would make sense.
The latter would only be appropriate in cases where such a higher level formulation already appears somewhere in the standard library, as is the case with collections.abc.Hashable
and functools.total_ordering
.
A couple of other characteristics that may fail into that "higher level" category would be to support copying and pickling objects by default and then have a boolean toggle to turn that off at the class level:
copy=True
: delegate copy & deepcopy support to the interpreter based on the defined fields, without getting into protocol details (complains if a defined field can't be copied & isn't excluded from copying)pickle=True
: delegate pickle support to the interpreter based on the defined fields, without getting into protocol details (complains if a defined field can't be pickled & isn't excluded from pickling)Since the PEP and reference implementation are finalizing, I'm going to close this. We can continue the discussion in the appropriate venue once the PEP is published.
Quoting @ncoghlan on python-ideas: