[IronPython] False? with Unit Test

Curt Hagenlocher curt at hagenlocher.org
Sun Apr 6 01:24:21 CEST 2008

On Sat, Apr 5, 2008 at 10:21 AM, Michael Foord
<fuzzyman at voidspace.org.uk> wrote:
> As bool inherits from int, calling 'sys.exit' with False ought to be
> exactly the equivalent of calling it with 0. (False == 0, True == 1).

SystemExitException.GetExitCode calls TypeCache.Int32.IsInstanceOfType
with the argument to the exit function, and this function returns
false when the type of the argument is System.Boolean.

In other words, this discrepancy happens because
TypeCache.Int32.IsInstanceOfType(false) == false
TypeCache.Int32.IsInstanceOfType(4) == true

Interestingly, a user-defined type that derives from "int" produces
the correct response.

Curt Hagenlocher
curt at hagenlocher.org

More information about the Ironpython-users mailing list