A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2000-December/010859.html below:

[Python-Dev] PEP 231, __findattr__()

[Python-Dev] PEP 231, __findattr__()M.-A. Lemburg mal@lemburg.com
Sat, 02 Dec 2000 11:03:11 +0100
"Barry A. Warsaw" wrote:
> 
> I've just uploaded PEP 231, which describes a new hook in the instance
> access mechanism, called __findattr__() after a similar mechanism that
> exists in Jython (but is not exposed at the Python layer).
> 
> You can do all kinds of interesting things with __findattr__(),
> including implement the __of__() protocol of ExtensionClass, and thus
> implicit and explicit acquisitions, in pure Python.  You can also do
> Java Bean-like interfaces and C++-like access control.  The PEP
> contains sample implementations of all of these, although the latter
> isn't as clean as I'd like, due to other restrictions in Python.
> 
> My hope is that __findattr__() would eliminate most, if not all, the
> need for ExtensionClass, at least within the Zope and ZODB contexts.
> I haven't tried to implement Persistent using it though.

The PEP does define when and how __findattr__() is called,
but makes no statement about what it should do or return...

Here's a slightly different idea:

Given the name, I would expect it to go look for an attribute
and then return the attribute and its container (this
doesn't seem to be what you have in mind here, though).

An alternative approach given the semantics above would
then be to first try a __getattr__() lookup and revert
to __findattr__() in case this fails. I don't think there
is any need to overload __setattr__() in such a way, because
you cannot be sure which object actually gets the new attribute.

By exposing the functionality using a new builtin, findattr(),
this could be used for all the examples you give too.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Company:                                        http://www.egenix.com/
Consulting:                                    http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4