[Python-3000] pep 3119 question (ABC)
Guido van Rossum
guido at python.org
Thu Jan 10 20:59:18 CET 2008
On Jan 10, 2008 11:54 AM, Neal Becker <ndbecker2 at gmail.com> wrote:
> Guido van Rossum wrote:
> > On Jan 10, 2008 11:20 AM, Neal Becker <ndbecker2 at gmail.com> wrote:
> >> On reading this pep, I was not clear on one issue.
> >> In some interface proposals (zope?), as well as in c++0x concept
> >> proposal, there is a mechanism to specify how to adapt a given class to
> >> satisfy given interface requirements.
> >> For example, suppose container ABC requires a 'size'. Suppose I have a
> >> container-like class C, but it's size is called 'len'. The idea is to be
> >> able to specify, _outside of the class C_, that the size requirement is
> >> met, and it's called 'len'.
> >> Does pep 3119 offer that functionality?
> > No.
> Isn't that rather limiting then? It's all well and good to design a
> monolithic library with a uniform use of concepts. But the motivation for
> adaptation is that you want to mix libraries from different sources that
> might not have coordinated in their design.
> Is this because python classes are always open, and so I can always
> add/modify their properties to conform to any interface, even without
> touching the library source code, and therefore I don't really need any
> other mechanism to adapt interfaces?
It's because nobody contributed a requirement for this feature to the
PEP discussion when it was being discussed. I wouldn't want to rely on
monkeypatching if it was a valid requirement.
You should be able to subclass the metaclass though to add this
feature if you want it. If you do it cleanly enough it could even be
added to the PEP (or rather a new PEP) and to the standard abc.py
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000