[Python-ideas] PEP 447 revisited

Ronald Oussoren ronaldoussoren at mac.com
Sun Jul 27 09:42:02 CEST 2014


On 26 Jul 2014, at 13:59, Nick Coghlan <ncoghlan at gmail.com> wrote:

> On 26 July 2014 18:03, Ronald Oussoren <ronaldoussoren at mac.com> wrote:
>> Hi,
>> 
>> After a long hiatus I’ve done some updates to PEP 447 which proposes a new metaclass method that’s used in attribute resolution for normal and super instances. There have been two updates, the first one is trivial, the proposed method has a new name (__getdescriptor__).  The second change to the PEP is to add a Python pseudo implementation of object.__getattribute__ and super.__getattribute__ to make it easier to reason about the impact of the proposal.
>> 
>> I’d like to move forward with this PEP, either to rejection or (preferable) to acceptance of the feature in some form. That said, I’m not too attached to the exact proposal, it just seems to be the minmal clean change that can be used to implement my use case for this.
>> 
>> My use case is fairly obscure, but hopefully it is not too obscure :-).  The problem I have at the moment is basically that it is not possible to hook into the attribute resolution algorithm used by super.__getattribute__ and this PEP would solve that.
> 
> The use case seems reasonable to me, and the new slot name seems much
> easier to document and explain than the previous iteration.

Some Australian guy you may know suggested the name the last time I posted 
the PEP for review, and I liked the name.  Naming is hard...

> 
> I'd like to see the PEP look into the inspect module and consider the
> consequences for the functions there (e.g. another way for
> getattr_static to miss methods), as well as any possible implications
> for dir(). We had a few issues there with the enum changes for 3.4
> (and some more serious ones with Argument Clinic) - it's not a
> blocker, it's just nice going in to have some idea of the impact going
> in :)

I agree that it is useful to explain those consequences. The consequences
for dir() should be similar to those for __getattribute__ itself: if you override
the default implementation you should implement __dir__ to match, or live
with the inconsistency.

There should be little or no impact on inspect, other then that getattr_static 
may not work as expected when using a custom implemention of __getdescriptor__
because the class __dict__ may not contain the values you need. There’s nothing
that can be done about that, the entire point of getattr_static is to avoid triggering
custom attribute lookup code.

inspect.getmembers and inspect.get_class_attrs, look directly at the class __dict__, 
and hence might not show everything that’s available through the class when using
a custom __getdescriptor__ method.  I have to think about the consequences and possible
mitigation of those consequences a bit, not just for this PEP but for the current PyObjC 
implementation as well.

Anyways, I’ll add a section about introspection to the PEP that describes these issues 
and their consequences.

Ronald

> 
> Cheers,
> Nick.
> 
> -- 
> Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia



More information about the Python-ideas mailing list