Proposal for removing self

Ravi Teja Bhupatiraju webraviteja at
Thu Aug 26 23:15:16 CEST 2004

aleaxit at (Alex Martelli) wrote in message news:<1gj4sup.hrowbz1bzo06mN%aleaxit at>...
> Ravi Teja Bhupatiraju <webraviteja at> wrote:
>    ...
> > <sample>
> > class FooBar:
> >     __public__ = [Name, Age]
> >     def setName(name):
> >         Name = name
> > </sample>
> Go ahead: learn about metaclasses and bytecode hacking and write your
> custom metaclass to perform this.  Except for the little detail that
> you'll never get away with not quoting 'Name' and 'Age' in the
> __public__ assignment, the rest is reasonably easy to perform.  Publish
> your metaclass and start campaigning for it.
> As long as you're just yakking about it ain't gonna happen -- become a
> metaclass and bytecode expert and you can implement this in Python, or
> convince somebody who is such an expert, for which the implementation
> should be the job of a couple days tops.
> > While I am complaining, a few other peeves ...
> > 
> > Another thing is I dislike is having to use __ for *every* private
> > variable. For *me* __private__ at the top of the class definition code
> > would be more elegant. __readonly__ would be another nicety.
> That's an even easier job for a custom metaclass with very modest amount
> of byecode hacking.  I suggest you start with this one, really truly
> VERY easy.  In fact you could probably do it without any actual hacking
> on the bytecode itself, just rewriting a few tables of strings in the
> code objects of the functions that are the methods of the class.
> One impossible task (THAT would require hacking the Python parser and
> changing things very deeply) as I already mentioned would be the form
> you want for the assignment to __public__ (or similarly to
> __private__etc).  Those names are undefined (or worse defined globally)
> and to teach Python (and human readers!) that for that one speclal case
> of assignment to __public__ (or __private__), THAT one case only,
> COMPLETELY different rules apply than ANYWHERE else in Python, well,
> it's just as difficult as it is absurd.
> I suggest you tackle the 'look ma no quotes!' task last, after
> everything else is working, because that one detail is going to take far
> longer than everything else put together, even if you're learning about
> metaclasses and bytecodes from scratch.
> > Introducing the above attributes into the language would not likely
> > break any existing Python code.
> If this peculiar behavior is limited to classes whose metaclass is your
> custom RaviSpecial, "not likely" becomes "absolutely impossible", a
> great enhancement.  One more reason to implement this in a metaclass.
> > Just my 2c.
> Well make it three cents and do an implementation, if you really care.
> Otherwise, it's just words...
> Alex

Aren't you being a bit touchy Alex? Now I am glad that I did not
mention my wish list on properties and DBC :-). However, your post has
been quite informative. So I can live with that.

I wish I could rise up to your challenge and do all that stuff.
Regretfully, my Python skills don't extend to metaclasses and
especially "byte code hacking". Maybe you will explain those in your
next edition of the cookbook :-).

That said, I only could find one set of docs that could be called a
<tutorial> on metaclasses. Those were by David Mertz and Michele
Simionato. I could not get through them. I took comfort in the
statement "Metaclasses are deeper magic than 99% of users should ever
worry about" from the document. I am still looking for something I can

More information about the Python-list mailing list