Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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; 'from:addr:yahoo.co.uk': 0.04; 'guido': 0.05; 'url:pipermail': 0.05; 'purpose.': 0.07; 'referring': 0.07; 'enormous': 0.09; 'lawrence': 0.09; 'override': 0.09; 'pep': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rossum': 0.09; 'def': 0.12; 'jan': 0.12; 'language.': 0.14; "wouldn't": 0.14; '460': 0.16; 'dict': 0.16; 'missing?': 0.16; 'multi-thread': 0.16; 'reboot': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'str):': 0.16; 'subclassing': 0.16; 'subject:subclasses': 0.16; 'substitution': 0.16; 'surprises': 0.16; 'language': 0.16; 'wrote:': 0.18; 'discussion': 0.18; '(where': 0.19; 'saying': 0.22; 'header:User-Agent:1': 0.23; 'least': 0.26; 'certain': 0.27; 'values': 0.27; 'header:X -Complaints-To:1': 0.27; 'van': 0.27; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; 'words': 0.29; 'involving': 0.30; "i'm": 0.30; 'that.': 0.31; 'you?': 0.31; "d'aprano": 0.31; 'keys': 0.31; 'noted': 0.31; 'steven': 0.31; 'violation': 0.31; 'class': 0.32; 'option': 0.32; 'another': 0.32; 'url:python': 0.33; 'comment': 0.34; 'date:': 0.34; 'skip:_ 10': 0.34; 'but': 0.35; 'add': 0.35; 'there': 0.35; "he's": 0.36; 'replies': 0.36; 'url:org': 0.36; 'too': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'list,': 0.38; 'rather': 0.38; 'subject:': 0.39; 'channel': 0.39; 'to:addr:python.org': 0.39; 'mailing': 0.39; 'received:org': 0.40; 'url:mail': 0.40; 'how': 0.40; 'lost': 0.61; 're:': 0.63; 'our': 0.64; 'more': 0.64; 'here': 0.66; 'bottom': 0.67; 'hoping': 0.75; '(oh': 0.84; '*really*': 0.84; '[python-dev]': 0.84; 'batchelder': 0.84; 'noise,': 0.84; 'python-dev': 0.84; 'url:python-dev': 0.84; 'dare': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Chanelling Guido - dict subclasses Date: Wed, 15 Jan 2014 09:10:38 +0000 References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-78-147-25-248.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 In-Reply-To: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> 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: 59 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389777056 news.xs4all.nl 2842 [2001:888:2000:d::a6]:35012 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63966 On 15/01/2014 01:27, Steven D'Aprano wrote: > Over on the Python-Dev mailing list, there is an ENORMOUS multi-thread > discussion involving at least two PEPs, about bytes/str compatibility. > But I don't want to talk about that. (Oh gods, I *really* don't want to > talk about that...) + trillions > > In the midst of that discussion, Guido van Rossum made a comment about > subclassing dicts: > > [quote] > From: Guido van Rossum > Date: Tue, 14 Jan 2014 12:06:32 -0800 > Subject: Re: [Python-Dev] PEP 460 reboot > > Personally I wouldn't add any words suggesting or referring > to the option of creation another class for this purpose. You > wouldn't recommend subclassing dict for constraining the > types of keys or values, would you? > [end quote] > > https://mail.python.org/pipermail/python-dev/2014-January/131537.html > > This surprises me, and rather than bother Python-Dev (where it will > likely be lost in the noise, and certain will be off-topic), I'm hoping > there may be someone here who is willing to attempt to channel GvR. I > would have thought that subclassing dict for the purpose of constraining > the type of keys or values would be precisely an excellent use of > subclassing. Exactly what I was thinking. > > > class TextOnlyDict(dict): > def __setitem__(self, key, value): > if not isinstance(key, str): > raise TypeError > super().__setitem__(key, value) > # need to override more methods too > > > But reading Guido, I think he's saying that wouldn't be a good idea. I > don't get it -- it's not a violation of the Liskov Substitution > Principle, because it's more restrictive, not less. What am I missing? > > Couple of replies I noted from Ned Batchelder and Terry Reedy. Smacked bottom for Peter Otten, how dare he? :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence