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


Groups > comp.lang.python > #83652

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

Path csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.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.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'true,': 0.05; 'puts': 0.07; 'defines': 0.09; 'doing?': 0.09; 'false,': 0.09; 'instance.': 0.09; 'useless': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'creates': 0.14; '12:59': 0.16; 'as- is': 0.16; 'bind': 0.16; 'bool': 0.16; 'distinct': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mean,': 0.16; 'ought': 0.16; 'parts,': 0.16; 'singleton': 0.16; 'subclass': 0.16; 'subclasses': 0.16; 'subclassing': 0.16; 'tuple,': 0.16; 'exception': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; "python's": 0.19; 'meant': 0.20; 'example': 0.22; 'cc:addr:python.org': 0.22; 'proxy': 0.24; 'replace': 0.24; 'cc:2**0': 0.24; 'define': 0.26; 'least': 0.26; 'header:In-Reply- To:1': 0.27; '[1]': 0.29; 'andrew': 0.30; 'nature': 0.30; 'message-id:@mail.gmail.com': 0.30; '13,': 0.31; '>>>>': 0.31; 'assert': 0.31; 'initialized': 0.31; 'class': 0.32; 'skip:b 30': 0.33; 'actual': 0.34; 'could': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'data,': 0.36; 'false': 0.36; 'instances': 0.36; 'two': 0.37; 'handle': 0.38; 'pm,': 0.38; 'expect': 0.39; 'even': 0.60; 'new': 0.61; 'first': 0.61; 'more': 0.64; 'determine': 0.67; 'helping': 0.70; 'url:v': 0.71; 'url:youtube': 0.71; 'url:watch': 0.77; '2015': 0.84; 'fail.': 0.84; 'pass:': 0.84; '2013,': 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=rHD+MDoYAO0gmoNrgU7gYvcCQjRASEc+uVQZHJThOQk=; b=OrCOy1muB4x1Nvr6nqe3S2RcdB82Y9g30erdDjvdfBtKWaL45rtgFZee+sLIAyRK90 KXtlONqarbdn4oExXmCH2aMve/5EBjynLTJSNrOdvgjVb9T7MImJw2NMZAUZ+GAYmUlZ vX7QXJ5xbPzmgHcSBpqE+uzSEWoKUwHc0vx1ukNPgtImSEd0ZRuVr/IltzSacg6RlxOa LIQgLhltwTUapE9V+6JEVyOHs4vqvU4lVMip3+6YLIx+EXLxPb+PcTa+EWOYZejlAl4x A3NbfbqqXRMyilANK/T1juW7OSYsuFzcCFCSoWctne3lPqfU2R7OP7kXCydu6lSZuvoh RPhQ==
MIME-Version 1.0
X-Received by 10.42.94.14 with SMTP id z14mr25875844icm.59.1421115072636; Mon, 12 Jan 2015 18:11:12 -0800 (PST)
In-Reply-To <54B47C0E.208@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> <CAPTjJmr0Bqcyj=VBADVSthSZ+pYMXQeNC-j8qLC2xHAVLUmcgA@mail.gmail.com> <54B47C0E.208@r3dsolutions.com>
Date Tue, 13 Jan 2015 13:11:12 +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.17651.1421115074.18130.python-list@python.org> (permalink)
Lines 62
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1421115074 news.xs4all.nl 2858 [2001:888:2000:d::a6]:41341
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83652

Show key headers only | View raw


On Tue, Jan 13, 2015 at 12:59 PM, Andrew Robinson
<andrew3@r3dsolutions.com> wrote:
> There is no need to copy data from an initialized superclass instance into a
> subclass instance that has no new data, but only rebind -- or add a
> binding/proxy object -- to bind the superclass instance to the subclass
> methods.
>
> eg: what is now standard practice to create a new copy of the superclass:
>
> class myFalse( bool ): __new__( self, data ): return super( myFalse, self
> ).__new__(self,data)
>
> Could be replaced by a general purpose proxy meant to handle singleton
> subclassing:
>
> class myFalse( bool ):  __new__( self ): return
> bind_superinstance_to_subclass( False, myFalse )

I don't understand. What do you expect this to be doing? Are you
trying to replace the original False with your new subclass?

>> he Python bool type has the following
>> invariant, for any object x:
>>
>> assert not isinstance(x, bool) or x is True or x is False
> I mean, even right now -- with the language as-is -- let's define something
> that blatantly creates a new instance of something neither an actual
> instance of True nor False, and make that x -- and see if your assertion
> catches it:
>
> Python 2.7.5 (default, May 29 2013, 02:28:51)
> [GCC 4.8.0] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> x=(False,)
>>>> assert not isinstance(x, bool) or x is True or x is False
>>>>
>
> LOL ... no exception was raised... and we know if the assertion Failed, an
> exception ought to be raised:

The assertion did not fail. There are three parts, and as long as one
of them is true, the assertion will pass:

1) x isn't an instance of bool
2) x is the object known as True
3) x is the object known as False

You just gave an example of the first part of the invariant. That's an
instance of tuple, which is not a subclass of bool, ergo isinstance(x,
bool) returns False, negating that makes True, and the assertion
passes. [1]

> So -- your assertion, at least as shown, is pretty useless in helping
> determine why subclassing is not allowed, or instances of subclasses that
> are not distinct from their superclasses existing instance.

It exactly defines the nature of Python's bool type: there are
precisely two instances of it.

ChrisA

[1] Which puts me in mind of https://www.youtube.com/watch?v=D0yYwBzKAyY

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


Thread

Re: Comparisons and sorting of a numeric class.... Chris Angelico <rosuav@gmail.com> - 2015-01-13 13:11 +1100

csiph-web