On 16 June 2016 at 14:17, Martin Teichmann <lkb.teichm...@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   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to