Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #83269
| References | <54ABB88A.7070504@r3dsolutions.com> <54ABC52A.1050507@davea.name> <54ABE383.3020801@r3dsolutions.com> |
|---|---|
| Date | 2015-01-07 00:35 +1100 |
| Subject | Re: Comparisons and sorting of a numeric class.... |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.17414.1420551359.18130.python-list@python.org> (permalink) |
On Wed, Jan 7, 2015 at 12:30 AM, Andrew Robinson <andrew3@r3dsolutions.com> 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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Comparisons and sorting of a numeric class.... Chris Angelico <rosuav@gmail.com> - 2015-01-07 00:35 +1100
csiph-web