[Python-Dev] PEP 487: Simpler customization of class creation (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Thu Jun 16 17:36:36 EDT 2016
- Previous message (by thread): [Python-Dev] PEP 487: Simpler customization of class creation
- Next message (by thread): [Python-Dev] PEP 487: Simpler customization of class creation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 16 June 2016 at 14:17, Martin Teichmann <lkb.teichmann at gmail.com> wrote:
As a side note, you propose to use OrderedDict as the class definition namespace, and this is exactly how I implemented it. Nonetheless, I would like to keep this fact as an implementation detail, such that other implementations of Python (PyPy comes to mind) or even CPython at a later time may switch to a different way to implement this feature. I am thinking especially about the option to determine the -order already at compile time. Sure, this would mean that someone_ could trick us by dynamically changing the order of attribute definition, but I would document that as an abuse of the functionality with undocumented outcome.
I don't think that's a side note, I think it's an important point (and relates to one of Nikita's questions as well): we have the option of carving out certain aspects of PEP 520 as CPython implementation details.
In particular, the language level guarantee can be that "class statements set definition_order by default, but may not do so when using a metaclass that returns a custom namespace from prepare", with the implementation detail that CPython does that by using collection.OrderedDict for the class namespace by default.
An implementation like PyPy, with an inherently ordered standard dict implementation, can just rely on that rather than being obliged to switch to their full collections.OrderedDict type.
However, I don't think we should leave the compile-time vs runtime definition order question as an implementation detail - I think we should be explicit that the definition order attribute captures the runtime definition order, with conditionals, loops and reassignment being handled accordingly.
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message (by thread): [Python-Dev] PEP 487: Simpler customization of class creation
- Next message (by thread): [Python-Dev] PEP 487: Simpler customization of class creation
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]