[Python-bugs-list] [ python-Bugs-474737 ] Problem overriding int.init() (original) (raw)
noreply@sourceforge.net noreply@sourceforge.net
Thu, 25 Oct 2001 05:43:54 -0700
- Previous message: [Python-bugs-list] [ python-Bugs-474836 ] Tix not included in windows distribution
- Next message: [Python-bugs-list] [ python-Bugs-474238 ] 2.2b1 src rpm doesn't include Lib/email/
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Bugs item #474737, was opened at 2001-10-24 21:48 You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=474737&group_id=5470
Category: Type/class unification
Group: Not a Bug Status: Closed Resolution: Invalid Priority: 5 Submitted By: Mark J (average) Assigned to: Guido van Rossum (gvanrossum) Summary: Problem overriding int.init()
Initial Comment: Given:
class I(int): def init(self, init_value, extra_param="test"): print extra_param int.init(self, init_value)
Python 2.2b1 (#1, Oct 19 2001, 23:11:09) [GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-81)] on linux2
i = I(1) #fine test #yes, new constructor used i 1 #value set correctly
i = I(2, "oops") Traceback (most recent call last): File "", line 1, in ? TypeError: an integer is required i = I(3, dummy="oops") Traceback (most recent call last): File "", line 1, in ? TypeError: dummy is an invalid keyword argument for this functionThanks,
Mark
Comment By: Guido van Rossum (gvanrossum) Date: 2001-10-25 05:43
Message: Logged In: YES user_id=6380
The constructor signature is shared by new and init; you have to override both to accept the new argument. Add
def new(cls, i=0, *args): return int.new(cls, i)
(I promise we'll document all this in enough detail eventually!)
You can respond by visiting: http://sourceforge.net/tracker/?func=detail&atid=105470&aid=474737&group_id=5470
- Previous message: [Python-bugs-list] [ python-Bugs-474836 ] Tix not included in windows distribution
- Next message: [Python-bugs-list] [ python-Bugs-474238 ] 2.2b1 src rpm doesn't include Lib/email/
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]