Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'third-party': 0.04; 'subject:Python': 0.06; 'float': 0.07; 'operand': 0.09; 'pep': 0.09; '"to': 0.16; 'ast': 0.16; 'excluded': 0.16; 'expects': 0.16; 'fuzzy': 0.16; 'instances,': 0.16; 'letting': 0.16; 'operand:': 0.16; 'roy': 0.16; 'subclass': 0.16; 'subclasses': 0.16; 'surprises': 0.16; 'typeerror:': 0.16; 'well-known': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'library': 0.18; 'examples': 0.20; '>>>': 0.22; 'specify': 0.24; 'developers': 0.25; '15,': 0.26; '2.0': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; '"",': 0.31; '>>>>': 0.31; 'apparently': 0.31; "d'aprano": 0.31; 'decimal': 0.31; 'libraries': 0.31; 'noted': 0.31; 'steven': 0.31; 'anyone': 0.31; 'file': 0.32; '(most': 0.33; 'guess': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; '14,': 0.36; 'false': 0.36; 'example,': 0.37; 'two': 0.37; 'implement': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'expect': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'easy': 0.60; 'ian': 0.60; 'kind': 0.63; 'skip:n 10': 0.64; 'answer.': 0.68; 'smith': 0.68; 'behavior': 0.77; 'article': 0.77; 'type(s)': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=jsO8VucXwheBMwseVegjwBDpdkUBelMFOWmNSIq7C3o=; b=u9lu91bi5weUXsmBxUP7lcbe+0KzFgBJmz2y+bR+NBt13ciG5rBm9BQsRk543HoOvs icCcww1xWYnyIpJax4ZlwtMQGOXZv983EDvHzwa/uFs5EJTJ+3TLWbGBnyK+Hj1Pv4w4 X261OUztxrrZHL3J+fArQe1agb1DFfnplxAbLVIwN3n8w75rod12ToyDImfUvU76xClX vcUJFvrCQuqVUq2yB1eH86Fpjq6sIryy/PDWFZmN0feZDjjVI0Qlr/NfNOF71s9s93tI bTzf+KWq3niYSG5LHib9rMd4KBlDY5aQM0TXwPWZGzAF5DFdNnlrS1LD4bYvFg+rAVQ5 Yy9Q== X-Received: by 10.236.8.103 with SMTP id 67mr11602727yhq.29.1402854347585; Sun, 15 Jun 2014 10:45:47 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <539d0a40$0$29988$c3e8da3$5496439d@news.astraweb.com> <539dbcbe$0$29988$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Sun, 15 Jun 2014 11:45:06 -0600 Subject: Re: Python's numeric tower To: Python 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: 38 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402854356 news.xs4all.nl 2841 [2001:888:2000:d::a6]:33608 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73295 On Sun, Jun 15, 2014 at 11:28 AM, Roy Smith wrote: > In article <539dbcbe$0$29988$c3e8da3$5496439d@news.astraweb.com>, > Steven D'Aprano wrote: > >> On Sun, 15 Jun 2014 01:22:50 -0600, Ian Kelly wrote: >> >> > On Sat, Jun 14, 2014 at 8:51 PM, Steven D'Aprano >> > wrote: >> >> Does anyone know any examples of values or types from the standard >> >> library or well-known third-party libraries which satisfies >> >> isinstance(a, numbers.Number) but not isinstance(a, numbers.Complex)? >> > >> >>>> issubclass(decimal.Decimal, numbers.Number) >> > True >> >>>> issubclass(decimal.Decimal, numbers.Complex) >> > False >> >> Well, that surprises and disappoints me, but thank you for the answer. > > Why would you expect Decimal to be a subclass of Complex? One might expect it for the same reason that float is a subclass of Complex. Decimal was intentionally excluded from the numeric tower (as noted in PEP 3141), but apparently it still subclasses Number. As I understand it the reason Decimal was excluded was because it doesn't fully implement the methods of Complex; for example, given two Complex instances, one expects to be able to add them, but that doesn't always hold for Decimal depending on the type of the other operand: >>> Decimal("2.0") + 2.0 Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for +: 'decimal.Decimal' and 'float' The Number ast doesn't specify any particular behavior and is there to "to make it easy for people to be fuzzy about what kind of number they expect", so I guess the developers so no harm in letting Decimal subclass it.