Message302599
Aye, the "C.__new__" example omitting the first arg was just an error in that example.
And that's a good point about the current "object.__init__()" error message actually being incorrect, since the *methods* each take exactly one argument - it's only the "object(*args, **kwds)" form that genuinely expects zero arguments.
If we were to correct that error as well, we'd end up with the following:
# Without any method overrides
class C:
pass
C(42) -> "TypeError: C() takes no arguments"
C.__new__(C, 42) -> "TypeError: C() takes no arguments"
C().__init__(42) -> "TypeError: C.__init__() takes exactly one argument"
# These next two quirks are the price we pay for the nicer errors above
object.__new__(C, 42) -> "TypeError: C() takes no arguments"
object.__init__(C(), 42) -> "TypeError: C.__init__() takes exactly one argument"
# With method overrides
class D:
def __new__(cls, *args, **kwds):
super().__new__(cls, *args, **kwds)
def __init__(self, *args, **kwds):
super().__init__(*args, **kwds)
D(42) -> "TypeError: object.__new__() takes exactly one argument"
D.__new__(D, 42) -> "TypeError: object.__new__() takes exactly one argument"
D().__init__(42) -> "TypeError: object.__init__() takes exactly one argument"
object.__new__(C, 42) -> "TypeError: object.__new__() takes exactly one argument"
object.__init__(C(), 42) -> "TypeError: object.__init__() takes exactly one argument" |
|
Date |
User |
Action |
Args |
2017-09-20 06:30:01 | ncoghlan | set | recipients:
+ ncoghlan, serhiy.storchaka |
2017-09-20 06:30:01 | ncoghlan | set | messageid: <1505889001.29.0.32614331273.issue31506@psf.upfronthosting.co.za> |
2017-09-20 06:30:01 | ncoghlan | link | issue31506 messages |
2017-09-20 06:30:01 | ncoghlan | create | |
|