Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Mark Lawrence Newsgroups: comp.lang.python Subject: Re: Suggestion: make sequence and map interfaces more similar Date: Thu, 31 Mar 2016 13:30:29 +0100 Lines: 58 Message-ID: References: <56f8836b$0$1602$c3e8da3$5496439d@news.astraweb.com> <56FA8C71.4050306@rece.vub.ac.be> <56fb677f$0$11121$c3e8da3@news.astraweb.com> <56fbf879$0$1591$c3e8da3$5496439d@news.astraweb.com> <56fc8f20$0$1600$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de ogP87OM0AYBwEpFRtInExQlg8M4xX50U74ymGFOAGb+w== 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; 'modify': 0.04; 'from:addr:yahoo.co.uk': 0.05; 'bytes.': 0.07; 'defines': 0.07; 'indices': 0.07; 'definition,': 0.09; 'dict': 0.09; 'immutable': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'str,': 0.09; 'python': 0.10; 'explicitly': 0.15; '2016': 0.16; 'contract.': 0.16; 'hypothetical': 0.16; 'integers.': 0.16; 'iterable': 0.16; 'lookups': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'sequence.': 0.16; 'stuff,': 0.16; 'subject:interfaces': 0.16; 'subject:make': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; 'element': 0.18; 'example.': 0.18; 'expanded': 0.18; 'integer': 0.18; 'thanks.': 0.18; 'language': 0.19; 'do.': 0.22; 'arguments': 0.22; 'assign': 0.22; 'keys': 0.22; 'lawrence': 0.22; 'examples': 0.24; 'header:In-Reply-To:1': 0.24; 'discussion': 0.24; 'header:User- Agent:1': 0.26; 'example': 0.26; 'header:X-Complaints-To:1': 0.26; 'rest': 0.26; 'sequence': 0.27; 'actual': 0.28; 'interface': 0.29; 'objects': 0.29; 'program,': 0.29; 'classes': 0.30; 'that.': 0.30; 'code': 0.30; 'skip:_ 10': 0.32; 'implement': 0.32; 'knows': 0.32; 'language.': 0.32; 'class': 0.33; 'url:python': 0.33; 'common': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'definition': 0.34; 'list': 0.34; 'could': 0.35; 'desirable': 0.35; 'mapping': 0.35; 'maps': 0.35; 'sometimes': 0.35; 'supports': 0.35; 'but': 0.36; 'list,': 0.36; 'should': 0.36; 'url:org': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'beyond': 0.37; 'mean': 0.38; 'google': 0.39; 'goes': 0.39; 'does': 0.39; 'enough': 0.39; 'takes': 0.39; 'rather': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'mark': 0.40; 'some': 0.40; 'url:3': 0.60; 'your': 0.60; 'subject:more': 0.61; 'real': 0.62; 'charset:windows-1252': 0.62; 'linked': 0.63; 'our': 0.64; 'march': 0.64; 'world': 0.64; 'python-list': 0.66; 'real-world': 0.66; 'here': 0.66; 'apart': 0.70; 'special': 0.73; 'offline,': 0.84; 'pythonistas,': 0.84; 'toy': 0.84; 'sulla': 0.91; 'production,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: 80.234.189.93 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.1 In-Reply-To: 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:106148 On 31/03/2016 12:58, Marco Sulla via Python-list wrote: > On 31 March 2016 at 04:40, Steven D'Aprano wrote: >> Enough of the hypothetical arguments about what one could do or might do. >> Let's see a concrete example of actual real world code used in production, >> not a mickey-mouse toy program, where it is desirable that adding or >> deleting one key will modify the rest of the keys in the mapping. > > > 1. the example was for confuting your assertion that an implementation > of sequences as extended classes of maps violate the map contract. > 2. I already linked a real-world example previously. Google it and you > can find tons of examples like that. > > > On 31 March 2016 at 04:44, Steven D'Aprano wrote: >> for a, b in zip(spam, eggs): >> # do some stuff, sometimes assign x[a] or b[a] or who knows what? >> >> >> Does this mean that "lists, dicts and zip" should all support the same >> interface? > > I do not understand what you mean with this example. A zip object is > not a sequence nor a map. My definition of sequences as "ordered maps > with integer keys that start from zero and have no gaps" is perfectly > valid as I demonstrated to you, while zip objects have nothing in > common with sequences and maps, apart the fact they are all iterables. > The definition of sequence is given here https://docs.python.org/3/glossary.html#term-sequence. An iterable which supports efficient element access using integer indices via the __getitem__() special method and defines a __len__() method that returns the length of the sequence. Some built-in sequence types are list, str, tuple, and bytes. Note that dict also supports __getitem__() and __len__(), but is considered a mapping rather than a sequence because the lookups use arbitrary immutable keys rather than integers. The collections.abc.Sequence abstract base class defines a much richer interface that goes beyond just __getitem__() and __len__(), adding count(), index(), __contains__(), and __reversed__(). Types that implement this expanded interface can be registered explicitly using register(). As this is a Python list the above definition clearly takes priority over your definition, so can you please take this discussion offline, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence