Test None for an object that does not implement ==

Chris Angelico rosuav at gmail.com
Sun Dec 25 09:04:06 EST 2011


On Mon, Dec 26, 2011 at 12:48 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> I can't think of any other un-subclassable classes other than NoneType.
> Which ones are you thinking of?

I don't remember, but it was mentioned in a thread a little while ago.
Experimentation shows that 'bool' is one of them, though. This may
shed some light:

>>> class Foo(type(iter)):
	pass

Traceback (most recent call last):
  File "<pyshell#103>", line 1, in <module>
    class Foo(type(iter)):
TypeError: type 'builtin_function_or_method' is not an acceptable base type

I think there are certain types that are actually not implemented as
classes, and hence cannot be subclassed. This is almost certainly an
implementation detail though; my testing was done in Py3.2 (on Windows
fwiw).

ChrisA



More information about the Python-list mailing list