[Python-Dev] PEP 520: Preserving Class Attribute Definition Order (round 5) (original) (raw)
Eric Snow ericsnowcurrently at gmail.com
Tue Jun 28 13:30:37 EDT 2016
- Previous message (by thread): [Python-Dev] PEP 520: Preserving Class Attribute Definition Order (round 5)
- Next message (by thread): [Python-Dev] PEP 520: Preserving Class Attribute Definition Order (round 5)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sun, Jun 26, 2016 at 5:55 PM, Guido van Rossum <guido at python.org> wrote:
On Fri, Jun 24, 2016 at 4:37 PM, Nick Coghlan <ncoghlan at gmail.com> wrote: > This version looks fine to me. Same to me, mostly.
I've updated the PEP per everyone's comments [1], except I still haven't dropped the read-only definition_order constraint. I'll do that when I resolve the open questions, on which I'd like some feedback:
What about slots?
In addition to including slots in definition_order, the
options I see are to either ignore the names in slots, put them into definition_order right after slots, or stick them in at the end (since their descriptors are added afterward). I'm leaning toward the first one, leaving the slot names out of definition_order since the names aren't actually part of the definition (slots itself is). Doing so doesn't lose any information and more closely reflects the class definition body.
- Allow setting definition_order in type()?
I don't see any reason to disallow "definition_order" in the namespace passed in to the 3 argument form of builtins.type(). Then dynamically created types can have a definition order (without needing to set cls.definition_order afterward).
- C-API for setting definition_order?
I'd rather avoid any extra complexity in the PEP due to diving into C-API support for creating types with a definition_order. However, if it would be convenient enough and not a complex endeavor, I'm willing to accommodate that case in the PEP. At the same time, at the C-API level is it so important to accommodate definition_order at class-creation time? Can't you directly modify cls.dict in C? Perhaps it would be safer to have a simple C-API function to set definition_order for you?
- Drop the "read-only attribute" requirement?
I really like that read-only implies "complete", which is a valuable message for definition_order to convey. I think that there's a lot to be said for communicating about a value in that way.
At the same time, most of the time Python doesn't keep you from fiddling with similar "complete" values (e.g. name, slots), so I see that point too. And since the interpreter (nor stdlib) doesn't rely on definition_order, it isn't much of a footgun (nor would setting definition_order be much of an attractive nuisance).
I suppose I'm having a hard time letting go of the attractiveness of "read-only == complete". However, given that you've been pretty clear what you think, I'm more at ease about it. :)
Anyway, thoughts on the above would be helpful. I'll try to be responsive so we can wrap this up.
-eric
[1] https://github.com/python/peps/blob/master/pep-0520.txt
- Previous message (by thread): [Python-Dev] PEP 520: Preserving Class Attribute Definition Order (round 5)
- Next message (by thread): [Python-Dev] PEP 520: Preserving Class Attribute Definition Order (round 5)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]