From: Laura C. <la...@op...> - 2015-12-08 03:34:40
|
In a message of Mon, 07 Dec 2015 14:25:26 -0700, Jim Baker writes: >Laura, > >Binary operations like + are compiled to Java bytecode to use >PyObject::_add; this in turn dispatches through PyObject::_basic_add, which >in turns goes through, for classes that derive from object, >PyObjectDerived::#__add__ with a boilerplate implementation like so: > > public PyObject __add__(PyObject other) { > PyType self_type=getType(); > PyObject impl=self_type.lookup("__add__"); > if (impl!=null) { > PyObject res=impl.__get__(this,self_type).__call__(other); > if (res==Py.NotImplemented) > return null; > return res; > } > return super.__add__(other); > } > >This means that the lookup is only against the type, not against the >object's __dict__. So we follow the same data model for special methods >that CPython uses. > >This process should inline well for the more common case of adding ints and >floats, which was the conclusion of the analysis that Cliff Click performed >a few years ago at the JVM Language Summit (as part of a study of Jython >and other alternative JVM languages). > >- Jim Good to hear. Every so often python-dev goes off and makes some momentous decision that has enormous impact on other python implementations without first checking with the other implementations to see exactly how much hardship this would cause. Glad to see I was wrong in this case. :) Laura |