Re: Subclassing int

2007-07-24 Thread Alex Popescu
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: >

Re: Subclassing int

2007-07-23 Thread G
Thanks a lot Matt and Steve. I replaced __int__ with __new__ and it worked On 7/23/07, Matt McCredie <[EMAIL PROTECTED]> wrote: Do you guys know why the if statement is not evaluated? For immutable types __new__ is called before __init__. There are some details here: http://docs.python.org/r

Re: Subclassing int

2007-07-23 Thread Steve Holden
G wrote: > 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