Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!bcyclone05.am1.xlned.com!bcyclone05.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!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.011 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'class,': 0.07; 'cc:addr :python-list': 0.11; '12:50': 0.16; '__new__': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hierarchy': 0.16; 'indent': 0.16; 'inheritance': 0.16; 'mutable': 0.16; 'route,': 0.16; 'subclass': 0.16; 'subject:Classes': 0.16; 'wrote:': 0.18; 'restrictions': 0.19; 'shape': 0.19; '+0000': 0.22; 'cc:addr:python.org': 0.22; 'creating': 0.23; 'fine': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'suggested': 0.26; 'header:In- Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'gives': 0.31; 'follows': 0.31; 'class': 0.32; 'probably': 0.32; 'another': 0.32; "i'd": 0.34; 'equal': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'skip:> 10': 0.36; 'level': 0.37; 'being': 0.38; 'nov': 0.38; 'simply': 0.61; "you're": 0.61; 'back': 0.62; 'square': 0.74; 'special': 0.74; 'potentially': 0.81; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=iLxJG1yB/5LmbwzaZ1cKYXfyziI5/VKs1gRZUnrTTo8=; b=WfOxxiddPvWgHNwwfVk+Lefy/P7XAdYqy1xrbyMz5bpECjvAwZGcf3VQnr5fJhl6rt 8ndQI/2HR7O2S9Us44MO3EA5FYyq0j/M3Utmom8ouy6XaJhZTkjYeXWy0ms572Ia1cO7 u6xPMHzLW8oMNYxmGMKrtKI4/03sdUuz+mF326r4kk7Kb1Bd/WrZIWAwncWeSKYMZgc3 IF1NSVoKehRA/HlrOmpScdOk390YjvbqUWJgL+W6cO/z5zcPuIZiBjDuaPweedPNc3BJ ByAgbsbdjuG4OyLrDsOK271YBo7X0qx3l64J6UfXbVwd3hj6ejPY8oIKM9cIDuS3KGk3 fVaw== MIME-Version: 1.0 X-Received: by 10.107.136.94 with SMTP id k91mr32131677iod.43.1415028870656; Mon, 03 Nov 2014 07:34:30 -0800 (PST) In-Reply-To: <1r1f5ahd8qjh8fk5a3dpjgo75s7ejf7064@4ax.com> References: <2i585a5s6d1aagbh6ot2b88i51o8jhq0db@4ax.com> <1r1f5ahd8qjh8fk5a3dpjgo75s7ejf7064@4ax.com> Date: Tue, 4 Nov 2014 02:34:30 +1100 Subject: Re: Classes From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415028873 news.xs4all.nl 2941 [2001:888:2000:d::a6]:38149 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 5044 X-Received-Body-CRC: 997293798 Xref: csiph.com comp.lang.python:80159 On Tue, Nov 4, 2014 at 12:50 AM, Dennis Lee Bieber wrote: > On Mon, 3 Nov 2014 03:12:32 +0000 (UTC), Denis McMahon > declaimed the following: > >>So: >> >>Quadrilateral >> Parallelogram >> Square >> Rectangle >> Rhombus >> Diamond (4 sides eq) >> Trapezoid >> Arrowhead >> >>Is an arrowhead a trapezoid? > > I'd probably indent square under rectangle, and indent diamond where it > is -- both being restrictions on rectangle/rhombus > > But we may need another category, convex and concave; the arrowhead > would fall into the concave grouping. That's fine if you're creating a taxonomical hierarchy of immutables, but neither works if you're creating a mutable class hierarchy that follows LSP. The only way you can make any of this work (as someone suggested earlier, I believe) is by having __new__ potentially return a subclass, so if you ask Parallelogram to give you one with all sides equal and all angles equal, it gives you back a Square. But since a square is a special form of rhombus as well as a special form of rectangle, you'd have to use multiple inheritance or an AST-style subclass hook to verify. Of course, if you're going down that route, you probably want to take this up a level and have a Shape class, and have the subclass hook simply check if it's four-sided as well. ChrisA