Subclassing int

G gggg.iiiii at gmail.com
Mon Jul 23 21:03:19 EDT 2007


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070723/b2648d48/attachment.html>


More information about the Python-list mailing list