Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.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.018 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'float': 0.07; 'methods,': 0.09; 'type,': 0.09; 'variables.': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'mostly': 0.14; 'changes': 0.15; 'bool': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'given,': 0.16; 'portable,': 0.16; 'subclassing': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'written': 0.21; '(in': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'class.': 0.26; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'andrew': 0.30; 'contract,': 0.30; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'that.': 0.31; 'bunch': 0.31; 'class': 0.32; 'compatible': 0.32; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'combination': 0.36; 'issue': 0.38; 'pm,': 0.38; 'either': 0.39; 'users': 0.40; 'skip:u 10': 0.60; 'algorithms': 0.60; 'tell': 0.60; 'new': 0.61; 'simple': 0.61; "you're": 0.61; 'first': 0.61; 'making': 0.63; 'special': 0.74; '2015': 0.84; 'way)': 0.84; 'disposal': 0.91; '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=eYYJZosFeaB8m/JnYchaSqa5ed7bEsyYPCfFblb8A4s=; b=ToR4TnqYf1lbfDjl6s3u2mmcDwQ2KCoPaboJCn9NMdk6TWJP7ISVrz6/ZafwctlvVb cWtGdLsgXwKZiCGzK8tTt2f/rMrhPIYXuKS6v9P+fUQ0JHLCSyaBQ1tcEpx6zzC3eJGC HKzGCImrR9vFKtXnMI6RsVhhlmEj8WgtMD056HdgTq2zGr2PU8AuC38Ied+vqMzGufH+ JOWGIIxUQ9qcOC7tvBrq8iuFBC7Ac5If1dZvmf25QzuSqQYBubTWTtMgU9m4mKxJIVHQ XWz/Jyh4s/VsnzUDl8ZJQnVxeGKDUua3TJ/ahFauBcCooNrpy9hFfVXE6syU5QXwasmS gJog== MIME-Version: 1.0 X-Received: by 10.42.95.12 with SMTP id d12mr1122039icn.12.1420597895852; Tue, 06 Jan 2015 18:31:35 -0800 (PST) In-Reply-To: <54AC97D9.4010504@r3dsolutions.com> References: <54ABB88A.7070504@r3dsolutions.com> <54ABC52A.1050507@davea.name> <54ABE383.3020801@r3dsolutions.com> <54AC97D9.4010504@r3dsolutions.com> Date: Wed, 7 Jan 2015 13:31:35 +1100 Subject: Re: Comparisons and sorting of a numeric class.... 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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420597904 news.xs4all.nl 2837 [2001:888:2000:d::a6]:35668 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83276 On Wed, Jan 7, 2015 at 1:20 PM, Andrew Robinson wrote: > Because defining a bunch of special methods defeats the very purpose of > making my class compatible with float variables. > eg: No legacy code would work... > > I know (belatedly) that am going to have to define my own class. > That's pretty much a given, but I want to do it in a way which requires my > users to make very few changes to their traditional floating point > algorithms and code. If you use a dedicated function instead of methods, that function can be written to take any combination of float and pseudo-float. > The type check issue is mostly about compatability in the first place ; eg: > users typecheck either unintentionally -- (novices syndrome) -- or because > they need all the capabilities of a given type, and the only simple way to > find out if they are all there are there is to typecheck. eg: That's the > whole point of subclassing bool ... to let the user know they have at their > disposal (in a portable, simple way) all the features of the base type. Thing is, you're not fulfilling bool's contract, so it's better to not subclass, and just make your new type always falsy. If your users are type-checking bools, you might just have to let it break, and tell them not to do that. ChrisA