Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed6.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; 'think,': 0.05; 'subject:object': 0.07; 'python': 0.08; 'rule.': 0.09; 'subclass': 0.09; 'subject:None': 0.09; 'am,': 0.12; 'received:209.85.210.174': 0.13; 'received:mail- iy0-f174.google.com': 0.13; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'metaclass': 0.16; 'roy': 0.16; 'subclassing': 0.16; 'yes;': 0.16; 'mon,': 0.16; 'wrote:': 0.18; '(most': 0.21; 'subject:not': 0.21; 'dec': 0.22; 'header:In-Reply- To:1': 0.22; 'traceback': 0.24; 'classes': 0.26; 'tried': 0.27; 'fact': 0.27; 'message-id:@mail.gmail.com': 0.28; 'error': 0.29; 'for,': 0.30; 'subject:Test': 0.30; 'typeerror:': 0.30; 'quite': 0.32; "can't": 0.32; 'rather': 0.33; 'to:addr:python-list': 0.34; 'calling': 0.34; 'last):': 0.34; 'none': 0.37; 'acceptable': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; "it's": 0.40; 'received:209': 0.40; 'to:addr:python.org': 0.40; 'type': 0.61; '2011': 0.61; 'ever': 0.65; '26,': 0.67; "'nonetype'": 0.84; '12:17': 0.84; 'deliberate': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=QzhTiNDvmfi5wx1+gt41pEi4uKclgPllOud745b81z8=; b=LHXy86pZqslVMFou+uXfpdJGLy9QsjcGldbSD4yFdmYMmmuC68HEqR1HbG0jD6lcI1 pNA9t0Hi6rfn30y4svdsG8JOiQF1+EdjU824KSS+TdUbPSS5qhwCprgUuZSK2EcORR+e pZYEacQUlk71/ihtsnT9WavPQCcwj0Cr2/AB4= MIME-Version: 1.0 In-Reply-To: References: <0d80ce25-9e65-4216-b26c-b8ee40f989a3@q9g2000yqe.googlegroups.com> Date: Mon, 26 Dec 2011 00:35:46 +1100 Subject: Re: Test None for an object that does not implement == From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 18 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1324820148 news.xs4all.nl 6864 [2001:888:2000:d::a6]:33999 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:17893 On Mon, Dec 26, 2011 at 12:17 AM, Roy Smith wrote: > Just for fun, I tried playing around with subclassing NoneType and > writing an __eq__ for my subclass. =A0Turns out, you can't do that: > > Traceback (most recent call last): > =A0File "./none.py", line 5, in > =A0 =A0class Nihil(NoneType): > TypeError: Error when calling the metaclass bases > =A0 =A0type 'NoneType' is not an acceptable base type Yes; unfortunately quite a few Python built-in classes can't be subclassed. It's an unfortunate fact of implementation, I think, rather than a deliberate rule. But then, what would you ever need to subclass None for, other than toys and testing? ChrisA