Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.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.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'override': 0.09; 'strings.': 0.09; 'def': 0.12; "wouldn't": 0.14; '-tkc': 0.16; 'dict': 0.16; 'does,': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'missing?': 0.16; 'str):': 0.16; 'subject:subclasses': 0.16; 'substitution': 0.16; 'wrote:': 0.18; 'seems': 0.21; 'saying': 0.22; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; 'behaving': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'violation': 0.31; 'class': 0.32; 'limitation': 0.33; 'skip:_ 10': 0.34; 'but': 0.35; "he's": 0.36; 'charset:us-ascii': 0.36; 'too': 0.37; 'to:addr :python-list': 0.38; 'to:addr:python.org': 0.39; 'more': 0.64; 'dict,': 0.84; 'received:50.22': 0.84 Date: Wed, 15 Jan 2014 05:03:25 -0600 From: Tim Chase To: python-list@python.org Subject: Re: Chanelling Guido - dict subclasses In-Reply-To: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> References: <52d5e408$0$29970$c3e8da3$5496439d@news.astraweb.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: authenticated_id: tim@thechases.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: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389783753 news.xs4all.nl 2933 [2001:888:2000:d::a6]:60304 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63969 On 2014-01-15 01:27, Steven D'Aprano wrote: > 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? Just as an observation, this seems almost exactly what anydbm does, behaving like a dict (whether it inherits from dict, or just duck-types like a dict), but with the limitation that keys/values need to be strings. -tkc