This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author ncoghlan
Recipients ncoghlan, serhiy.storchaka
Date 2017-09-20.06:30:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1505889001.29.0.32614331273.issue31506@psf.upfronthosting.co.za>
In-reply-to
Content
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"
History
Date User Action Args
2017-09-20 06:30:01ncoghlansetrecipients: + ncoghlan, serhiy.storchaka
2017-09-20 06:30:01ncoghlansetmessageid: <1505889001.29.0.32614331273.issue31506@psf.upfronthosting.co.za>
2017-09-20 06:30:01ncoghlanlinkissue31506 messages
2017-09-20 06:30:01ncoghlancreate