Subclassing int

G gggg.iiiii at
Tue Jul 24 03:03:19 CEST 2007


    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

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list