Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #103821
| From | eryk sun <eryksun@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: What arguments are passed to the __new__ method ? |
| Date | 2016-03-01 15:09 -0600 |
| Message-ID | <mailman.83.1456866603.20602.python-list@python.org> (permalink) |
| References | <56d5d043$0$632$426a74cc@news.free.fr> <nb4u0g$tes$1@ger.gmane.org> |
On Tue, Mar 1, 2016 at 2:27 PM, Terry Reedy <tjreedy@udel.edu> wrote: > On 3/1/2016 12:24 PM, ast wrote: > >> class Premiere: >> def __init__(self, price): >> pass >> p = Premiere(1000) >> >> which is OK. > > Premiere is callable because it inherits object.__call__. That function, or > the implementation of the CALL FUNCTION bytecode, must notice that > Premiere.__new__ is object.__new__, by inheritance, and only pass Premiere > and not 1000. It's not handled in bytecode or __call__. In CPython the type_call function passes its args and kwds to the type's tp_new and tp_init functions without modification. object.__new__ ignores the excess arguments in this case, as described in my previous message. While I think the cases where object.__new__ and object.__init__ ignore excess arguments are practical and sensible, they should still be documented. AFAICT, the language reference has nothing to say on this matter.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
What arguments are passed to the __new__ method ? "ast" <nomail@invalid.com> - 2016-03-01 18:24 +0100
Re: What arguments are passed to the __new__ method ? eryk sun <eryksun@gmail.com> - 2016-03-01 13:54 -0600
Re: What arguments are passed to the __new__ method ? Terry Reedy <tjreedy@udel.edu> - 2016-03-01 15:27 -0500
Re: What arguments are passed to the __new__ method ? eryk sun <eryksun@gmail.com> - 2016-03-01 15:09 -0600
Re: What arguments are passed to the __new__ method ? "ast" <nomail@invalid.com> - 2016-03-02 10:23 +0100
Re: What arguments are passed to the __new__ method ? Steven D'Aprano <steve@pearwood.info> - 2016-03-02 22:02 +1100
Re: What arguments are passed to the __new__ method ? Peter Pearson <pkpearson@nowhere.invalid> - 2016-03-02 17:40 +0000
Re: What arguments are passed to the __new__ method ? Rob Gaddi <rgaddi@highlandtechnology.invalid> - 2016-03-02 17:57 +0000
Re: What arguments are passed to the __new__ method ? Ian Kelly <ian.g.kelly@gmail.com> - 2016-03-02 11:26 -0700
csiph-web