Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39161

Re: Differences creating tuples and collections.namedtuples

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 <oscar.j.benjamin@gmail.com>
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> <mailman.1972.1361222953.2939.python-list@python.org> <5122c4d7$0$29982$c3e8da3$5496439d@news.astraweb.com>
From Oscar Benjamin <oscar.j.benjamin@gmail.com>
Date Tue, 19 Feb 2013 01:43:12 +0000
Subject Re: Differences creating tuples and collections.namedtuples
To "Steven D'Aprano" <steve+comp.lang.python@pearwood.info>
Content-Type text/plain; charset=ISO-8859-1
Cc Python List <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1991.1361238215.2939.python-list@python.org> (permalink)
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

Show key headers only | View raw


On 19 February 2013 00:18, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Differences creating tuples and collections.namedtuples John Reid <johnbaronreid@gmail.com> - 2013-02-18 03:47 -0800
  Re: Differences creating tuples and collections.namedtuples Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-18 12:03 +0000
  Re: Differences creating tuples and collections.namedtuples Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-18 12:05 +0000
  Re: Differences creating tuples and collections.namedtuples Dave Angel <davea@davea.name> - 2013-02-18 07:11 -0500
  Re: Differences creating tuples and collections.namedtuples John Reid <johnbaronreid@gmail.com> - 2013-02-18 13:49 +0000
  Re: Differences creating tuples and collections.namedtuples John Reid <johnbaronreid@gmail.com> - 2013-02-18 13:51 +0000
  Re: Differences creating tuples and collections.namedtuples John Reid <j.reid@mail.cryst.bbk.ac.uk> - 2013-02-18 14:09 +0000
    Re: Differences creating tuples and collections.namedtuples raymond.hettinger@gmail.com - 2013-02-18 23:48 -0800
      Re: Differences creating tuples and collections.namedtuples Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-19 08:06 +0000
      Re: Differences creating tuples and collections.namedtuples Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-19 08:57 +0000
      Re: Differences creating tuples and collections.namedtuples Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-19 08:06 +0000
      Re: Differences creating tuples and collections.namedtuples Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-19 08:05 +0000
    Re: Differences creating tuples and collections.namedtuples raymond.hettinger@gmail.com - 2013-02-18 23:48 -0800
  Re: Differences creating tuples and collections.namedtuples Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-18 14:15 +0000
  Re: Differences creating tuples and collections.namedtuples John Reid <johnbaronreid@gmail.com> - 2013-02-18 14:18 +0000
  Re: Differences creating tuples and collections.namedtuples Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-18 14:12 +0000
  Re: Differences creating tuples and collections.namedtuples John Reid <j.reid@mail.cryst.bbk.ac.uk> - 2013-02-18 14:23 +0000
  Re: Differences creating tuples and collections.namedtuples Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-18 14:53 +0000
  Re: Differences creating tuples and collections.namedtuples John Reid <j.reid@mail.cryst.bbk.ac.uk> - 2013-02-18 15:07 +0000
  Re: Differences creating tuples and collections.namedtuples Terry Reedy <tjreedy@udel.edu> - 2013-02-18 16:28 -0500
    Re: Differences creating tuples and collections.namedtuples Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-19 11:18 +1100
      Re: Differences creating tuples and collections.namedtuples Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-02-19 01:43 +0000
        Re: Differences creating tuples and collections.namedtuples Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-19 14:06 +1100
          Re: Differences creating tuples and collections.namedtuples Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-02-19 21:27 +1300
      Re: Differences creating tuples and collections.namedtuples Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-02-19 20:54 +1300
      Re: Differences creating tuples and collections.namedtuples John Reid <j.reid@mail.cryst.bbk.ac.uk> - 2013-02-19 09:30 +0000
      Re: Differences creating tuples and collections.namedtuples Terry Reedy <tjreedy@udel.edu> - 2013-02-19 22:38 -0500
        Re: Differences creating tuples and collections.namedtuples Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-22 10:38 +0000
      Re: Differences creating tuples and collections.namedtuples Chris Angelico <rosuav@gmail.com> - 2013-02-20 17:50 +1100
        Re: Differences creating tuples and collections.namedtuples Roy Smith <roy@panix.com> - 2013-02-20 09:09 -0500
    Re: Differences creating tuples and collections.namedtuples Roy Smith <roy@panix.com> - 2013-02-18 20:11 -0500
  Re: Differences creating tuples and collections.namedtuples alex23 <wuwei23@gmail.com> - 2013-02-18 17:47 -0800
    Re: Differences creating tuples and collections.namedtuples John Reid <j.reid@mail.cryst.bbk.ac.uk> - 2013-02-19 09:36 +0000

csiph-web