Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.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; 'python,': 0.02; 'c++,': 0.07; 'error:': 0.07; 'important,': 0.07; 'subject:help': 0.08; 'inherited': 0.09; 'latter': 0.09; 'oop': 0.09; 'type,': 0.09; 'cc:addr:python-list': 0.11; '(note': 0.16; 'cc:name:python list': 0.16; 'foo()': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hierarchy.': 0.16; 'inheritance': 0.16; 'instance:': 0.16; 'janssen': 0.16; 'subclass': 0.16; 'subject:object': 0.16; 'typedef': 0.16; 'typeerror:': 0.16; 'types,': 0.16; 'unambiguous': 0.16; 'unavailable': 0.16; 'worst': 0.16; 'language': 0.16; 'wrote:': 0.18; 'machine': 0.22; '>>>': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'integer': 0.24; 'module,': 0.24; 'parse': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'appear': 0.29; '[1]': 0.29; 'am,': 0.29; 'dec': 0.30; 'message- id:@mail.gmail.com': 0.30; '"",': 0.31; 'apparently': 0.31; 'struct': 0.31; 'types.': 0.31; 'file': 0.32; 'class': 0.32; 'probably': 0.32; '(most': 0.33; 'entirely': 0.33; 'maybe': 0.34; 'subject:the': 0.34; 'basic': 0.35; "can't": 0.35; 'created': 0.35; 'objects': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'acceptable': 0.36; 'c++': 0.36; 'in.': 0.36; 'keyword': 0.36; 'error.': 0.37; 'two': 0.37; 'clear': 0.37; 'being': 0.38; 'expected': 0.38; 'fact': 0.38; 'recent': 0.39; 'structure': 0.39; 'skip:u 10': 0.60; 'is.': 0.60; 'most': 0.60; 'here:': 0.62; 'different': 0.65; 'here': 0.66; 'useful.': 0.68; 'presumably': 0.84; 'subject:base': 0.84; 'to:none': 0.92; 'from.': 0.93; '2013': 0.98 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:content-transfer-encoding; bh=0Djcpjhobp5fhYUDd1L9WNmMW3oMf0D+btOAx/jFhQg=; b=KpUjtpFT3B27leCRejRKdffRVjdoQdG+H6UWvJixgMwiE69fRgpBFjCHaw9W11rRVE 9FAW4wcNhgn1M0IVtwDH7iY/cXfqWcTonr26YFqVC6fUFdrQGRNddSUQ5jyHD/3oXbKC TDJJBxSUjfXcdGXBDBME3QSa1BFZyrNFZTvjIRDceCQU/WhVcl5GRFkjN3GwmLhq8pFv qd24OBkollGrKf6T7rqUFbSCMA3auNF8NuBPYCI48VSOmzmzZeEqoy3sFJFjnSdf6wvV NXrc+ioWvqM4F3ULPrYclf25UhiX56EzMSNAV8Sn1FMtW90tybEU2ZaIhwIjwRvhZ7vh W07g== MIME-Version: 1.0 X-Received: by 10.66.164.136 with SMTP id yq8mr18352589pab.67.1386557041351; Sun, 08 Dec 2013 18:44:01 -0800 (PST) In-Reply-To: References: <52a44afc$0$30003$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 9 Dec 2013 13:44:01 +1100 Subject: Re: interactive help on the base object From: Chris Angelico Cc: Python List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: 64 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1386557044 news.xs4all.nl 2865 [2001:888:2000:d::a6]:55250 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61348 On Mon, Dec 9, 2013 at 10:01 AM, Mark Janssen w= rote: > (Note bene: as a comparison, C++ is very UNAMBIGUOUS about > this fact -- all objects inherit from concrete machine types, which is > why it remains important, *despite* being one of the worst to do OOP > in. Its *type model* is probably the most clear of any > object-oriented language). Factually wrong. In C++, it is actually *impossible* to inherit from a "concrete machine type", by which presumably you mean the classic types int/char/float etc. struct foo: public int { foo() {} }; 1.cpp:1:20: error: expected class-name before =E2=80=98int=E2=80=99 1.cpp:1:20: error: expected =E2=80=98{=E2=80=99 before =E2=80=98int=E2=80= =99 1.cpp:2:1: error: expected unqualified-id before =E2=80=98{=E2=80=99 token Okay, that's a parse error. Maybe if we avoid the language keyword? typedef int integer; struct foo: public integer { foo() {} }; 1.cpp:4:1: error: expected class-name before =E2=80=98{=E2=80=99 token Nope. There are two completely different groups here: the basic types (called here [1] "Fundamental data types") and the structure types. The latter are created by the struct/class keyword and can use inheritance. The former... aren't. Not every C++ type is part of the type hierarchy. This is actually somewhat true of Python, too, but the set of types that are unavailable for inheritance is much smaller and less useful. You can't inherit from the 'function' type, for instance: >>> class foo(type(lambda:1)): pass Traceback (most recent call last): File "", line 1, in class foo(type(lambda:1)): TypeError: type 'function' is not an acceptable base type And yet inherits from class <'object'>, so it's not entirely outside in the way C++ int is. And I can apparently subclass module, though not generator, and unsurprisingly NoneType can't be inherited from. (Though you can instantiate it, and it's probably the only class that will appear to have no return value from instantiation.) C++ has you *compose* structs/classes from primitives, but this is not the same as inheritance. They're completely separate concepts. ChrisA [1] http://www.cplusplus.com/doc/tutorial/variables/