Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'api.': 0.04; 'sufficient': 0.05; 'constructor': 0.07; 'expectation': 0.09; 'satisfy': 0.09; 'subclasses': 0.09; 'terry': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'violates': 0.09; 'cc:addr:python-list': 0.10; 'assume': 0.11; 'bounds': 0.16; 'cc:name:python list': 0.16; 'contract.': 0.16; 'feature?': 0.16; 'mistake.': 0.16; 'namedtuple': 0.16; 'namedtuples': 0.16; 'reedy': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'tuples,': 0.16; 'written.': 0.16; 'wrote:': 0.17; 'instance': 0.17; '>>>': 0.18; 'written': 0.20; 'all,': 0.21; 'cc:2**0': 0.23; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'am,': 0.27; 'implemented': 0.27; 'message- id:@mail.gmail.com': 0.27; 'received:209.85.212': 0.28; "d'aprano": 0.29; 'obj': 0.29; 'sensible': 0.29; 'steven': 0.29; 'no,': 0.29; 'class': 0.29; 'related': 0.30; 'point': 0.31; '(and': 0.32; 'problem.': 0.32; 'could': 0.32; 'doubt': 0.33; 'problem': 0.33; 'received:google.com': 0.34; 'list': 0.35; 'requiring': 0.35; 'said,': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'but': 0.36; 'should': 0.36; 'beyond': 0.37; 'signature': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'john': 0.60; 'kind': 0.61; 'gone': 0.64; '2013': 0.84; 'functions)': 0.84; 'oscar': 0.84; 'reid': 0.84; 'unclear': 0.84; 'mistake': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=Ft+tSHkAIP4hyiS/yIgfkj3m5WX9eJQPG38h4fCNuG4=; b=DR5FzsQ0WZt3J0oscYTUkjaPAiIttph0/yjI91QnTKtn6JdZQOmb2C3KPFFpIQa3oV +42f3EK0OyNkLOFeXlYhVNjMj9f9nMPU324pmIcAcsOHd+lTsj573OAU80ZmPGEI2FGs EYYLY23No6qHmuKCmIYLscenvj9/yelenDu56uvODyqfWrbbRFIGMgtlF7qCHKJ0AN3N xX88aVbQGSzJstO/0Cu4/NfDWnQvOhkoicTljKdLH3sHJ5cQiNZBzMat1k2i8PuYhKOY tWvKLC1472ERiP2AoKFS543AdcaLtaySniB+FVwvrhw/0fN70lEqgRmLGdU85B8+7i9Y h4bg== X-Received: by 10.52.23.18 with SMTP id i18mr16004396vdf.46.1361238212672; Mon, 18 Feb 2013 17:43:32 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <5122c4d7$0$29982$c3e8da3$5496439d@news.astraweb.com> References: <7a40a426-baa9-46f8-8f9d-59ba32b044f3@googlegroups.com> <5122c4d7$0$29982$c3e8da3$5496439d@news.astraweb.com> From: Oscar Benjamin Date: Tue, 19 Feb 2013 01:43:12 +0000 Subject: Re: Differences creating tuples and collections.namedtuples To: "Steven D'Aprano" Content-Type: text/plain; charset=ISO-8859-1 Cc: Python List X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1361238215 news.xs4all.nl 6907 [2001:888:2000:d::a6]:40155 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:39161 On 19 February 2013 00:18, Steven D'Aprano wrote: > Terry Reedy wrote: >> On 2/18/2013 6:47 AM, John Reid wrote: [snip] >>> Is this a problem with namedtuples, ipython or just a feature? >> >> With canSequence. If isinstance was available and the above were written >> before list and tuple could be subclassed, canSequence was sensible when >> written. But as Oscar said, it is now a mistake for canSequence to >> assume that all subclasses of list and tuple have the same >> initialization api. > > No, it is not a mistake. It is a problem with namedtuples that they violate > the expectation that they should have the same constructor signature as > other tuples. After all, namedtuples *are* tuples, they should be > constructed the same way. But they aren't, so that violates a reasonable > expectation. It is a mistake. A namedtuple class instance provides all of the methods/operators provided by a tuple. This should be sufficient to fill the tuplishness contract. Requiring that obj satisfy a contract is one thing. When you get to the point of requiring that type(obj) must do so as well you have gone beyond duck-typing and the normal bounds of poly-morphism. It's still unclear what the purpose of canSequence is, but I doubt that there isn't a better way that it (and its related functions) could be implemented that would not have this kind of problem. Oscar