Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4a.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; 'guido': 0.05; 'that?': 0.05; 'class,': 0.07; 'detect': 0.07; 'float': 0.07; 'modified': 0.07; 'aliases': 0.09; 'method,': 0.09; "people's": 0.09; 'received:172.16.0': 0.09; 'type,': 0.09; 'variables.': 0.09; 'wrapper': 0.09; 'jan': 0.12; 'mostly': 0.14; "wouldn't": 0.14; 'changes': 0.15; 'bool': 0.16; 'check?': 0.16; 'detected': 0.16; 'distinct': 0.16; 'given,': 0.16; 'instance;': 0.16; 'operator.': 0.16; 'portable,': 0.16; 'subclass': 0.16; 'subclassing': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'things.': 0.19; 'written': 0.21; 'seems': 0.21; 'memory': 0.22; 'example': 0.22; '(in': 0.22; 'coding': 0.22; 'separate': 0.22; 'tests': 0.22; 'header:User-Agent:1': 0.23; 'question': 0.24; 'sort': 0.25; 'class.': 0.26; 'define': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'chris': 0.29; 'received:172.16': 0.29; 'am,': 0.29; 'andrew': 0.30; 'returned': 0.30; "i'm": 0.30; 'code': 0.31; 'bunch': 0.31; 'comparison': 0.31; 'existence': 0.31; 'class': 0.32; 'compatible': 0.32; 'checking': 0.33; 'totally': 0.33; 'skip:_ 10': 0.34; 'something': 0.35; 'objects': 0.35; 'but': 0.35; 'add': 0.35; 'there': 0.35; 'really': 0.36; 'crazy': 0.36; 'false': 0.36; 'method': 0.36; 'searching': 0.37; 'to:addr:python-list': 0.38; 'issue': 0.38; 'rather': 0.38; 'ability': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'either': 0.39; 'users': 0.40; 'even': 0.60; 'skip:u 10': 0.60; 'algorithms': 0.60; 'break': 0.61; 'new': 0.61; 'simple': 0.61; 'first': 0.61; 'making': 0.63; 'name': 0.63; 'received:phx3.secureserver.net': 0.65; 'received:prod.phx3.secureserver.net': 0.65; 'special': 0.74; '2015': 0.84; 'received:68.178.252': 0.84; 'way)': 0.84; 'disposal': 0.91; 'received:68.178': 0.91 Date: Tue, 06 Jan 2015 18:20:09 -0800 From: Andrew Robinson User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Comparisons and sorting of a numeric class.... References: <54ABB88A.7070504@r3dsolutions.com> <54ABC52A.1050507@davea.name> <54ABE383.3020801@r3dsolutions.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1420597202 news.xs4all.nl 2836 [2001:888:2000:d::a6]:60198 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:83275 On 01/06/2015 05:35 AM, Chris Angelico wrote: > On Wed, Jan 7, 2015 at 12:30 AM, Andrew Robinson > wrote: >> Why this is so important to Guido, I don't know ... but it's making it VERY >> difficult to add named aliases of False which will still be detected as >> False and type-checkable as a bool. If my objects don't type check right -- >> they will likely break some people's legacy code... and I really don't even >> care to create a new instance of the bool object in memory which is what >> Guido seems worried about, rather I'm really only after the ability to >> detect the subclass wrapper name as distinct from bool False or bool True >> with the 'is' operator. If there were a way to get the typecheck to match, >> I wouldn't mind making a totally separate class which returned the False >> instance; eg: something like an example I modified from searching on the >> web: > Okay, so why not just go with your own class, and deal with the > question of the type check? Simple solution: Instead of fiddling with > __gt__/__lt__, create your own method, and use your own comparison > function to sort these things. > > ChrisA 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. 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. Well, if I make a new object -- type checking is pointless. No user thinking they were coding for floating point in the past would know that my new return type is totally compatible with bool. They would have to have written individual tests for the existence of every method in bool, and why would they be crazy enough to do that? It's a lot of work for nothing...