was: Re: looking for MOP documentation

Christian Tanzer tanzer at swing.co.at
Fri Sep 19 03:18:40 EDT 2003


Peter Hansen <peter at engcorp.com> wrote:

> Alan Kennedy wrote:
> >
> > Peter Hansen wrote:
> > > Key phrase: "Metaobject protocols are interfaces to the language
> > > that give users the ability to incrementally modify the language's
> > > behavior and implementation...".  Near as I can tell, part of the
> > > whole character of Python is that a user *cannot* do either of
> > > those things.
> >
> > Hmm, does this rephrasing hold any truth?
> >
> > "Metaclasses are interfaces to the python language
> > that give users the ability to incrementally modify the language's
> > behavior and implementation...".
> >
> > Isn't modifying standard behaviour the whole purpose of metaclasses?
>
> But it doesn't really modify the *language's* behaviour in the way
> implied by a simplistic reading of the above phrase.  That is, the
> "obvious" interpretation is that syntax and grammar are being affected,
> not just the behaviour of one small slice of the language, specifically
> how classes behave.  In some languages the two things are not so
> separate, but in Python they seem to be.

Are you sure?

Python 2.2.3 (#1, Jun 18 2003, 15:54:07)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Nasty(type) :
...   def __new__(cls,name,bases,d):
...     return 1
...
>>> class Surprise(object):
...   __metaclass__ = Nasty
...
>>> Surprise
1
>>> type(_)
<type 'int'>
>>>

Ducks-and-runs,

-- 
Christian Tanzer                                         tanzer at swing.co.at






More information about the Python-list mailing list