[C++-sig] strange behavior with respect to numeric and Booleanoverloads

Matthew Scouten (TT) Matthew.Scouten at tradingtechnologies.com
Tue Mar 17 15:25:30 CET 2009

isinstance( True, int ) returns True

However, the code 

 def foo( arg ):
     if isinstance( arg, bool ):
          _foo_bool( arg )
          _foo_other( arg )

Would work in theory. 

I could do this. I'm just annoyed that BP is not doing it for me. 

-----Original Message-----
cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org
[mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at py
thon.org] On Behalf Of Hans Meine
Sent: Tuesday, March 17, 2009 5:03 AM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] strange behavior with respect to numeric and

On Monday 16 March 2009 22:52:16 Ralf W. Grosse-Kunstleve wrote:
> [...] Boost.Python 2 was written when the Python bool type still
> was an int (Python 2.2). [...]

On Tuesday 17 March 2009 06:40:14 Roman Yakovenko wrote:
> Python code:
> def foo( arg ):
>     if isinstance( arg, int ):
>          _foo_int( arg )
>     else:
>          _foo_bool( arg )

Now I am confused.  Both of the above read as if a boolean was no longer
int, but I interpret "is a" and "isinstance" as checking for types
from, too?!  While Ralf could have meant (True is 1) with his "really",
above code should first test whether isinstance( arg, bool ), no?

Or did this change with 2.6/3?

Cplusplus-sig mailing list
Cplusplus-sig at python.org

More information about the Cplusplus-sig mailing list