FEEDBACK WANTED: Type/class unification

chris liechti cliechti at mails.ch
Sat Jul 28 22:56:46 EDT 2001


Guido van Rossum <guido at python.org> wrote in news:cp66cd12yp.fsf at cj20424-
a.reston1.va.home.com:
> Note that if you have concerns about backwards incompatibilities, the
> best thing you can do is point them out ASAP.  I want to ensure that
> 2.2 (final) is as compatible with 2.1 as possible, while still
> providing the new exciting features that type/class unification makes
> possible.

I like what i see in the intro and PEPs. especially the examples for the 
dictionary make sense.
the __get__ and __set__ for attributes sound interesting.. my colegue who 
is a delphi programmer can not understand that other languages don't have 
these...maybe this makes it easier for me to persuade him to use python :-)

why 2.2? this would also fit in a 3.0 along with a unified number system 
and true division. this would make a clean cut and a new better "python 
3.0" would be the choice for new projects and beginners. as you pointed 
out, in perl there was a similar cut from 4 to 5 (well python won't be very 
incompatible, just some modules need an update). 

will this also allow to replace the default generators for builtin 
types/type-classes? i mean that i can replace "int", "float", "complex",... 
with my own factories, say to implement my own number tower with rationals 
(if they weren't included anyway).

something like that:
--------
class rational:    	#intentional small caps first letter to make it
	    	    	    	#look like the other factories ("int", "long",...)
    	def __init__(self, numerator, denumerator):
    	    	self.numerator, self.denumerator = numerator, denumerator
    	def __int__(self):
    	    	return self.numerator / self.denumerator
    	def __div__(self, divisor):
    	    	return rational( self.numerator, self.denumerator*divisor )
    	... #plus all the other operators that make it a useful number object

class Myint(int):
    	def __div__(self, divisor):
    	    	return rational(self.value, divisor)
    	...

#same as Myint for complex,float,long,....

__builtins__.int = Myint
__builtins__.long = Mylong
...

#then in use:
a = 1/2    	    	    	#this should use the "Myint" factory for "1"
    	    	    	    	#and "2" because the default "int" was replaced
	    	    	    	#above
print type(a)    	    	#should say"<type 'instance'>", in detail an
	    	    	    	#instance of "Rational"

--------
this would also allow a change for the fixed point numeric arithmetic some 
people want for their caclculations with money. but i don't see that as a 
type which should be included in python itself but rather added by the 
people who need it realy.


PS: the link in 
    	http://python.sourceforge.net/peps/pep-0253.html
under "References" is broken. actually the "</A>" HTML tag is misplaced. 
maybe your PEP to HTML script needs to learn about "," in URLs.. ;-)

-- 
chris <cliechti at mails.ch>




More information about the Python-list mailing list