Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #83644

Re: Comparisons and sorting of a numeric class....

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.014
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'source.': 0.07; 'false,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'bool': 0.16; 'exist.': 0.16; 'fiddle': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'happily': 0.16; 'instantiated': 0.16; 'merely': 0.16; 'subclass': 0.16; 'subclassing': 0.16; '(you': 0.16; 'wrote:': 0.18; 'cc:addr:python.org': 0.22; 'replace': 0.24; 'cc:2**0': 0.24; 'class.': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'andrew': 0.30; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; '13,': 0.31; 'assert': 0.31; 'class': 0.32; 'there.': 0.32; 'worked': 0.33; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'data,': 0.36; 'false': 0.36; 'even': 0.60; 'most': 0.60; 'new': 0.61; 'name': 0.63; 'containing': 0.69; "'true'": 0.84; '2015': 0.84; 'huh?': 0.84; 'safe.': 0.84; '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=kP6rTMfCUH+jSpNHunoKMFkWBP+vcLRfZRWMqddb6ik=; b=ylVQESiT7VAQ/LcI8HAs9fq+GaBkwld3ib2TCA+8Bc7lYWBFXnqZis5vfO/K6O4S8q gcmXgrdrYJhD4kQ6E4tYNom+z4mXKtaEfNoxcLhizxKn5IZFIfnE0h03fM6TmPB8Huej qxIhFYV9mpvbqi0USWwGRUjpAOF613J0oPIRk37OTjmGt1mLUJdkiHC71lNow+PoowGH tKRteJycZHf2tIxkRZ/NCjadViAnTAx3Ld2gtRXEDoFcbVpBhnz2CB/ma3F1zB63qfNp LmzO5OZYGXMYRLKlz7pn9/Af0MdLa7vv6VknRH/54LPmtuDDGAu1k/OliNj8ip2mNVh3 IogA==
MIME-Version 1.0
X-Received by 10.50.62.104 with SMTP id x8mr9064265igr.2.1421102144112; Mon, 12 Jan 2015 14:35:44 -0800 (PST)
In-Reply-To <54B44A64.7010105@r3dsolutions.com>
References <54ABB88A.7070504@r3dsolutions.com> <54ABC52A.1050507@davea.name> <54ABE383.3020801@r3dsolutions.com> <CAPTjJmpktyHfghEr+cjPrhso7JgB4VfS4=5Gdi95gT0aFbSYGA@mail.gmail.com> <54AC97D9.4010504@r3dsolutions.com> <CAPTjJmooTK_+HVoeyeSrqBHN1=YjRYQ2kfDyQtL9JoA9SbTqsQ@mail.gmail.com> <54ACAA04.60801@r3dsolutions.com> <54ADC99F.3020405@stoneleaf.us> <54B44A64.7010105@r3dsolutions.com>
Date Tue, 13 Jan 2015 09:35:43 +1100
Subject Re: Comparisons and sorting of a numeric class....
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.17645.1421102146.18130.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1421102146 news.xs4all.nl 2888 [2001:888:2000:d::a6]:45461
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83644

Show key headers only | View raw


On Tue, Jan 13, 2015 at 9:27 AM, Andrew Robinson
<andrew3@r3dsolutions.com> wrote:
> Huh? I'm not adding any values when I merely subclass bool ; and even if the
> subclass could be instantiated -- that's doesn't mean a new value or
> instance of the base class (bool) must exist.  For I could happily work with
> a new subclass that contains no new data, but only an already existing
> instance of 'True' or 'False' as its value source.   That means there is no
> new value...  but at most (and even that could be worked around) a new
> instance of a subclass containing an existing instance of it's base class.

If you subclass bool and instantiate your subclass, you have made a
new instance of bool, because every instance of a subclass is an
instance of its superclass. The Python bool type has the following
invariant, for any object x:

assert not isinstance(x, bool) or x is True or x is False

(You can fiddle with this in Py2 by rebinding the names True and
False, but you could replace those names with (1==1) and (1==0) if you
want to be completely safe. Likewise, the name "bool" could be
replaced with (1==1).__class__ to avoid any stupidities there. But
conceptually, that's the invariant.)

Subclassing bool breaks this invariant, unless you never instantiate
the subclass, in which case it's completely useless.

ChrisA

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: Comparisons and sorting of a numeric class.... Chris Angelico <rosuav@gmail.com> - 2015-01-13 09:35 +1100
  Re: Comparisons and sorting of a numeric class.... Steven D'Aprano <steve@pearwood.info> - 2015-01-13 04:57 +0000
    Re: Comparisons and sorting of a numeric class.... Chris Angelico <rosuav@gmail.com> - 2015-01-13 16:30 +1100

csiph-web