G <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]:
> ------=_Part_187401_13883248.1185238999144 > Hi, > > I am trying to subclass int to allow a constructor to accept None. > I am > trying the following > > class INT(int): > def __init__(self, x): > if x is None: > return None > else: > int.__init__(x) > > b = INT(x=None) > > When i run the previous code i get the following error: > b = INT(x=None) > TypeError: int() argument must be a string or a number, not > 'NoneType'. > > Do you guys know why the if statement is not evaluated? > > Thanks for your help > Afaik __init__ must not return something. It is __new__ where you can do these kind of tricks. bests, ./alex -- .w( the_mindstorm )p. -- http://mail.python.org/mailman/listinfo/python-list