Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Marco Sulla Newsgroups: comp.lang.python Subject: Re: Suggestion: make sequence and map interfaces more similar Date: Wed, 30 Mar 2016 21:35:59 +0200 Lines: 59 Sender: forwardedby@e4ward.com Message-ID: References: <56f8836b$0$1602$c3e8da3$5496439d@news.astraweb.com> <56FA8C71.4050306@rece.vub.ac.be> <56fb677f$0$11121$c3e8da3@news.astraweb.com> <56fba7d3$0$1616$c3e8da3$5496439d@news.astraweb.com> <56fbc518$0$1593$c3e8da3$5496439d@news.astraweb.com> <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> Reply-To: mail.python.org@marco.sulla.e4ward.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de qXSV0lNo2aroXqUvZCAfrAwdqbNtaPzxWmr2rS6icl4A== Return-Path: <25194.gmail.com@bounce.e4ward.com> X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'behave': 0.09; 'dict': 0.09; 'rules.': 0.09; 'stable.': 0.09; 'exception': 0.13; 'index': 0.13; 'argument': 0.15; '2016': 0.16; 'arbitrary.': 0.16; 'disables': 0.16; 'hashable': 0.16; 'lookups': 0.16; 'mean,': 0.16; 'ordereddict': 0.16; 'pairs': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'subject:interfaces': 0.16; 'subject:make': 0.16; 'thinker,': 0.16; 'useless': 0.16; 'valid.': 0.16; 'wrote:': 0.16; 'basically': 0.18; 'implementing': 0.18; 'so.': 0.22; 'friend.': 0.22; 'keys': 0.22; 'code,': 0.23; 'insert': 0.23; 'sets': 0.23; 'header:In-Reply-To:1': 0.24; 'not.': 0.27; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'contract,': 0.27; 'finally,': 0.27; 'sequence': 0.27; 'values': 0.28; 'container': 0.29; 'extending': 0.29; 'methods.': 0.29; 'objects': 0.29; 'class.': 0.30; 'extend': 0.31; 'point': 0.33; 'class': 0.33; 'url:python': 0.33; "d'aprano": 0.33; 'ones,': 0.33; 'steven': 0.33; 'true.': 0.33; 'changing': 0.34; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'header:Received:8': 0.35; 'lists.': 0.35; 'mapping': 0.35; 'maps': 0.35; 'quite': 0.35; 'item': 0.35; 'supports': 0.35; 'but': 0.36; 'list,': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'child': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'expect': 0.37; 'method': 0.37; 'say': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'url:3': 0.60; 'your': 0.60; 'subject:more': 0.61; 'different': 0.63; 'march': 0.64; 'fall': 0.66; 'header:Reply-To:1': 0.67; 'act': 0.67; 'dear': 0.67; '8bit%:21': 0.70; 'reply-to:no real name:2**0': 0.71; 'concept.': 0.84; 'confusing': 0.84; 'received:23': 0.84; 'terrible': 0.84 Authentication-Results: dfw.e4ward.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=e4ward.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=e4ward.com; h= reply-to:content-transfer-encoding:content-type:content-type :subject:subject:message-id:date:date:from:from:references :in-reply-to:mime-version; s=mail; t=1459366609; x=1459453010; bh=qbkkN46AFlnUVvPDyGMvB6+90vdt5/FvkH8tPc9EJ7Q=; b=owPc8+uvXVp5 BoBKE+hCMPQn5NKPEW8uX/kvQtdwtddg2TAWxW4cKMrsmSLgjZbGpG0Nkg4WgTRg 1/b9BvUqxubew4V9H9acYWtCL1zImmL31NKTBR4QfaYm8bG8OIRYnDTF1Ldmwym6 IyVRtUJSz9POFQam6MFGiN/w7clynpo= Authentication-Results: dfw.e4ward.com (amavisd-new); dkim=fail (2048-bit key) reason="fail (message has been altered)" header.d=gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:content-transfer-encoding; bh=qbkkN46AFlnUVvPDyGMvB6+90vdt5/FvkH8tPc9EJ7Q=; b=XWGo3A5uNDLP96B1ycgeirDmTOFGeK9TsGedSlmdBFkd4RT1WHhq3zTebNj+w64I+Q zLmF5WyCwb+QKWlfxGIplaC6eoQIp2lc9sQbDw6UWzHrEFcibThg2gJMwZcXjgkw3pEt EN1cKGUUi5oQLVYAplSbYdSo8cqh2G3ejsRnTsAUeM2oGzhn3dDA8zR+c5P5Nqz2T3ig dTFNO2Mx4TPH8DDywenW5gQ7Tot6ekvVgv+u3GLc0YiC8smBvWtQAl2IeBlXeu0yu+o3 AuBaAKb5vmXEszr6m4n2R4lQv1xHzd1rEa5QFzyiHM7o0r9ti3Vw4zgD/85U6i9qTpYO 2FTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:content-transfer-encoding; bh=qbkkN46AFlnUVvPDyGMvB6+90vdt5/FvkH8tPc9EJ7Q=; b=efQ9VN3OVg6eOIG88ff0u6phvoytP4nKJ57+xrMcCCcM4rp45Fok7O6IoI7pWxxCef biLiTSun7FlexckFAsntryQ8Swb68MxnQ9ijzYT/ULzo7uHv773+H91W0SCpnO4kQ9+B zjOZD3wsXiks6kHUHAsJUDwJUdr9B5upczMq8Jlhf9WEBgBa5D+eQ4LfPz8pY8jqLk9O Bx0PlPQftQGZAVRHcQNd+lq3aKoqoP2T3eYlqw77f6Y8BfmEAPu71USWl+tIUB+VCJhV Y3ACo7Ze72I+rxS2/KjI/SR0XvstXOBDWr6HW7x88hI+rgGBA5+4jdVafmROyJ56cHbj vfow== X-Gm-Message-State: AD7BkJKNVbQZkJl/LCHBv06BOw6SMhVjtl/CYOV9HsiiSzNJnQEISWcVLXVVrA17SrpxUdrvbAkB45Uxl46Avg== X-Received: by 10.50.78.8 with SMTP id x8mr2266586igw.78.1459366598786; Wed, 30 Mar 2016 12:36:38 -0700 (PDT) In-Reply-To: <56fbf73d$0$1591$c3e8da3$5496439d@news.astraweb.com> X-Google-Sender-Auth: Z1ZlaDTP5PlLdq2DK-N8dhJf08g X-e4ward-RCPT: python-list.python.org-mail.python.org.marco.sulla.e4ward.com@ftcw4rx8877.reply.e4ward.com X-e4ward-x: . X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:106109 On 30 March 2016 at 02:55, Terry Reedy wrote: > To me [seq.items() and seq.keys()] are useless and confusing duplications= since enumerate()(seq) > and range(len(seq)) are quite different from dict.items and dict.keys. It's true. Indeed IMHO it's enumerate() that will be a confusing duplicatio= n. On 30 March 2016 at 02:55, Terry Reedy wrote: > At least in CPython, changing a dict disables view iterators. OrderedDict does not. On 30 March 2016 at 07:43, Steven D'Aprano wrote: > This is not an argument about dicts being mutable, because clearly they > aren't. This is an argument about key:value pairs being stable. So you basically say "I expect to get the value x from key y". Let me apply your point of view to lists. In lists, I expect to get the value x from index y. If I insert an item in a position before index y, I expect to get x at index y+1. But what if I write a class with a method insertPlus() that sets None at y+1 and x at y+2? I can say it does not violate the list contract, since you're extending the base class and implementing a new method that is not present in base class. If you extend a dict to act as a list, you're only adding *constraints* to existing methods and adding new methods. You're not completely change the existing ones, so the implementation is perfectly valid. Finally, let me quote the official docs: A mapping object maps hashable values to arbitrary objects [...] A dictionary=E2=80=99s keys are almost arbitrary values [...] https://docs.python.org/3/library/stdtypes.html#dict Mapping:A container object that supports arbitrary key lookups https://docs.python.org/3/glossary.html#term-mapping A sequence satisfies all these requirements, with the only exception that keys are not arbitrary. But no one will tell you that a child class that make a *restriction* over the original one will break rules. On 30 March 2016 at 17:56, Steven D'Aprano wrote: > If the OP wants to create his own "StrangeDict", which he himself describ= ed > as "terrible", then he can do so. But to make all dicts and lists behave = in > this "terrible" and "strange" way is a terrible idea. You did not understand well what I mean, my dear friend. I applied the word "terrible" to my code, not to the concept. You've demonstrated that a fair thinker, so do not fall in the temptation to play with words.