[Python-Dev] bool does not want to be subclassed?

Tim Peters tim.one at comcast.net
Fri Feb 13 18:48:23 EST 2004


[Joshua Marshall]
> ...
> So a different question...  Can it be relied upon that two expressions
> which both evaluate to False both return the same object?

Yes.

> That is, is it incorrect for a Python interpreter not to do this?

Yes.

> I find this in the Python Reference Manual: "for immutable types,
> operations that compute new values may actually return a reference to
> any existing object with the same type and value" (note the "may").
> Are bool and NoneType the only types for which this is reliably the case?

Type objects are also singletons (e.g., type(True) returns the same object
as type(False); ditto type("True") and type("False") and type("xyz"); etc).




More information about the Python-Dev mailing list