From: Samuele P. <ped...@bl...> - 2004-11-08 21:45:23
|
George Sakkis wrote: > I want to make the factory builtin functions (int,float,list,dict, etc.) > aliases to the respective type in types.*, as in python >= v2.2. As it is, > code such as > isinstance(3,int) and int(4.56) == 4 > which is valid in current python, fails in jython. The simple > int = types.IntType > solves the isinstance(3,int) problem but breaks the int(4.56), because > IntType's constructor does not coerce the argument to int. I tried to > rebind int.__init__ to my own function but this doesn't work either. Is > this doable at all ? Thanks, no, if you mean not touching the source, __init__ is cached in the form of a PyReflectedConstructor. Btw, this is already implemented on the branch, although it is still not enabled for all types. Jython 2.2aNewstyle on java1.4.0_02 (JIT: null) Type "copyright", "credits" or "license" for more information. >>> x=int(1.45) >>> x 1 >>> x.__class__ <type 'int'> >>> type(x) <type 'int'> >>> type(x) is int 1 >>> isinstance(x,int) 1 >>> isinstance(x,object) 1 >>> int.__new__(int,"0xa",0) 10 >>> but there types are not PyJavaClasses anymore, a proper __new__ being one the reasons. |