[Python-Dev] attaching methods to an object at runtime and compiler enhancement ideas...

kasper b. graversen kbg at kadnet.dk
Fri Oct 10 12:11:37 EDT 2003


Hello all.

This is my first posting here. My name is Kasper Graversen, a ph.d. student of the it-university of copenhagen. I'm playing with python for doing roles, that is, runtime specialization pr.v object with the ability of multiple views on each object. So far it has been fun playing with python, but I ponder why it is only possible to introduce functions and not methods to object instances?

I am also wondering if it is possible to change the parsed code at compile time by gaining access to the AST and by the use of some mechanism (somewhat similar to meta classes) to be able to patch in before the execution of the code

Finally, one of the most difficult things of moving from Java to python is the lack of checking done by the compiler ;) Here are two things I really miss which if would like the future versions of the compiler to support:


* A flag, when set, checks that each __init__ method calls its super __init__


* A flag, when set, checks that an inner class in a subclass by the same name of its supers inner class subclasses this class. Oddly only methods and not also inner classes are virtual by default in Python.
eg 
class A(object):
    class B(object):

class C(A):
    class B(object):

should raise an error since C.B should extend A.B


* A flag, when set, raises an error if an a field is introduced in code outside the __init__() block.. this ensures that spelling mistakes are caught at compile time,  when misspelling the field to be accessed.


sincerely
 Kasper B. Graversen
please help save our planet! At least click daily on
http://rainforest.care2.com/  and   http://www.therainforestsite.com/
and tell your friends to do the same...




More information about the Python-Dev mailing list