Proposal for removing self

Alex Martelli aleaxit at yahoo.com
Thu Aug 26 09:30:37 EDT 2004


Ravi Teja Bhupatiraju <webraviteja at yahoo.com> 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



More information about the Python-list mailing list