A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-February/124131.html below:

[Python-Dev] Rationale for different signatures of tuple.__new__ and namedtuple.__new__

[Python-Dev] Rationale for different signatures of tuple.__new__ and namedtuple.__new__Hrvoje Niksic hrvoje.niksic at avl.com
Mon Feb 18 16:02:10 CET 2013
On 02/18/2013 03:32 PM, John Reid wrote:
> I can do
>
> tuple([1,2,3])
>
> but not:
>
> from collections import namedtuple
> namedtuple('B', 'x y z')([1,2,3])
>
> I get a TypeError: __new__() takes exactly 4 arguments (2 given)
> However I can do:
>
> namedtuple('B', 'x y z')._make([1,2,3])
>
> So namedtuple's _make classmethod looks a lot like tuple's __new__().
> What's the rationale for this? Wouldn't it be better to share the same
> signature for __new__?

Sharing the constructor signature with tuple would break the common case of:

namedtuple('B', 'x y z')(1, 2, 3)

More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4