[Python-Dev] PEP 520: Preserving Class Attribute Definition Order (round 5)

Eric Snow ericsnowcurrently at gmail.com
Fri Jun 24 21:28:34 EDT 2016


On Fri, Jun 24, 2016 at 5:56 PM, Random832 <random832 at fastmail.com> wrote:
> On Fri, Jun 24, 2016, at 17:52, Eric Snow wrote:
>> - 2 open questions (__slots__?  drop read-only requirement?)
>
> It's worth noting that __slots__ itself doesn't have a read-only
> requirement. It can be a tuple, any iterable of strings, or a single
> string (which means the object has a single slot).

That is somewhat orthogonal to this PEP.

>
> Should dir() iterate in the order of __definition_order__? What, if so,
> should be done about instance attributes, or attributes of multiple
> classes, or class attributes not present in __definition_order__?

dir() relates to the object's namespace, not its class's definition namespace.

>
> What happens to classes whose __prepare__ doesn't return an OrderedDict?

The PEP already indicates that __definition_order__ will be set to None.

>
> Can __definition_order__ be reassigned at runtime?

That is the subject of one of the open questions.  Guido has suggested
that it should.  I don't agree, but then I'm not Dutch. :)

> Will it have the same
> constraints?

Given that folks generally shouldn't be setting it at runtime, there
isn't much point to constraining it. :)

>
> What if a metaclass defines __getattribute__ in a way that specially
> handles __definition_order__? If someone really wants to put a non-tuple
> there they will find a way. How hard do we want to think about ways to
> stop consenting adults from doing weird things with the
> __definition_order__ attribute?

The point of "consenting adults" is that the person breaking the rules
is aware that they are doing so and that they are willing to accept
the consequences.  Also, note that the interpreter does not depend on
__definition_order__ in any way.  As I say in the PEP, I'd rather
__definition_order__ remain read-only until there's a need.

-eric


More information about the Python-Dev mailing list