Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Marco S." Newsgroups: comp.lang.python Subject: Re: Suggestion: make sequence and map interfaces more similar Date: Sun, 27 Mar 2016 20:01:27 +0200 Lines: 29 Sender: forwardedby@e4ward.com Message-ID: References: Reply-To: mail.python.org@marco.sulla.e4ward.com Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de a6plIi8D/XxWaTfZCg2LnghoJzRlEQ1pXob12uDQzyqA== Return-Path: <27743.gmail.com@bounce.e4ward.com> X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'received:209.85.223': 0.03; 'incompatible': 0.07; 'dict': 0.09; 'immutable': 0.09; 'mutable': 0.09; 'stable.': 0.09; 'violates': 0.09; 'bug': 0.10; 'missed': 0.15; 'contract.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subclassing': 0.16; 'subject:interfaces': 0.16; 'subject:make': 0.16; 'wrote:': 0.16; 'integer': 0.18; 'keys': 0.22; 'lawrence': 0.22; 'suppose': 0.22; 'insert': 0.23; 'patch': 0.24; 'header:In-Reply-To:1': 0.24; 'least': 0.27; 'message-id:@mail.gmail.com': 0.27; 'contract,': 0.27; 'sequence': 0.27; 'values': 0.28; 'interface': 0.29; 'starts': 0.29; 'code': 0.30; 'extend': 0.31; 'point': 0.33; 'useful': 0.33; 'class': 0.33; 'problem': 0.33; "d'aprano": 0.33; 'ones,': 0.33; 'ordered': 0.33; 'steven': 0.33; 'add': 0.34; 'lists': 0.34; 'received:google.com': 0.35; 'header:Received:8': 0.35; 'lists.': 0.35; 'maps': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'to:addr:python- list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:209': 0.38; 'why': 0.39; 'easily': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'your': 0.60; 'relationship': 0.61; 'provide': 0.61; 'subject:more': 0.61; 'more': 0.63; 'between': 0.65; 'inherit': 0.66; 'header:Reply-To:1': 0.67; 'reply-to:no real name:2**0': 0.71; 'briefly,': 0.84; 'dict.': 0.84; 'received:23': 0.84; 'on?': 0.91 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-type:content-type:subject:subject:message-id :date:date:from:from:references:in-reply-to:mime-version; s= mail; t=1459101729; x=1459188130; bh=7OOyj87uC+/KOz/Amf37aZ+pHPM JFiobvr4biy+WIaE=; b=RjHXDFV9EZHT9D7INmuBbLSXmztsHvlBk5WwAb4WBds AU0hoLj/njtXjsFIFiduzZQckElgKvB3Bcj9Jv6VfFlNasrfrTUnQ2N/d0dhj7gg 4SpoL4WbOezTCM7UWajHv0o3v0pjHuxt8a0bX8LGLNRc7iLmek3OhL16pr8souJQ = 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:in-reply-to:references:from:date:message-id:subject:to; bh=7OOyj87uC+/KOz/Amf37aZ+pHPMJFiobvr4biy+WIaE=; b=wbrM5NI3FNNqbKERwaI77fLLw7ljPdmKkmsHRDh/LpraTuD8myMOPknBShm8lTfwGr fewunBqRF8N1e819mhZOCiKNiLrrduWCoXYylJHliNXYzynQCwisCQ/5vxioz6SI9evC cYvmMYy5jM/zwlpIXNyoDvHkyQe6auOWa6P6j+tNqgfqUkO4m3q3WMLIVqsO7qR/1KWR bugtgYLNs6dPyJB32b0BC/O6L7GozdyaftvHP5iW6O76vEJKX+3oQhaff9wYz9I1Dj5x 6NbV+67PhQtyVXgqxX0Rof6hxsshzC4ERlOxc2MCM9eivg+TqXYNnKvOPTtMzWm2SzqR 2Kow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=7OOyj87uC+/KOz/Amf37aZ+pHPMJFiobvr4biy+WIaE=; b=bgA48V0Qxms//q9Yu8h5WQmI+VhFvr6FeWacHpGFX80YKHJo55E72WFzYKVgsq+R7V NSqp3qvIIAshsCYkoYOXsVopr5POlC2wCnkqOiDtin/jY6Mhbei/H1ZomyzGnUKX3umL LZ0NQD7oWO1I8cnv8Pt8kqbcNPufuiagWI+8wscltvwslaRAis2A3LbqB+8fpSI3ej5f xxN652HxRH3YVhx62pG4QY2IIgK50jXa/3hPVXsJzw+4AU3aIXwtFbRYWcDzk/BijtAn +R2k0i1K2pyeNZSqvIMIA5LvMyvQXahpQ97oJ4Sn1DOMNOH0r7rmn8CWNbqrw3yCWxiQ cTDw== X-Gm-Message-State: AD7BkJKBliKlOG2FBj7hhZ4d8Rl1E1La6tGr8HgF4ytdylYkE0xzvmtl9iV00y71icBoCmcf7iyOpAySJU/jRg== X-Received: by 10.107.168.81 with SMTP id r78mr21769592ioe.179.1459101727219; Sun, 27 Mar 2016 11:02:07 -0700 (PDT) In-Reply-To: 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:105866 Steven D'Aprano wrote: > The point you might have missed is that treating lists as if they were > mappings violates at least one critical property of mappings: that the > relationship between keys and values are stable. This is true for immutable maps, but for mutable ones, you can simply do map[key] = new_value You can easily create a new class that extend dict and add to it a method that emulated the insert method of lists. It will definitively not break any contract, if your contract is "sequences are maps with ordered integer keys that starts from zero and have no gaps". Mark Lawrence wrote: > I cannot see this happening unless you provide a patch on the bug > tracker. However I suspect you can get the same thing by subclassing > dict. Why don't you try it and let us know how you get on? The problem with a vdict is that I should also create by zero a new interface (ABC), since MutableMapping have an incompatible contract. And to be much more useful I should code it inc C, and my C skills are not so magnificent. Furthermore I would try to create a new sequence interface that inherit from the vdict interface. More briefly, I need much free time. But I suppose I can start with something quick and dirty.