1
Vote

bool value conversion malfunctions with Iron python libraries

description

I am finding an issue with iron python libraries while passing a boolean value
 
Say I have python code "booltest.py" like below.
 
if ip_bool is not True and ip_bool is not False :
print "invalid ip_bool"
And when I call it using Iron Python libraries
 
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
 
scope.SetVariable("ip_bool", false);
scope = engine.ExecuteFile("booltest.py", scope);
 
this results in printing 'invalid ip_bool' though its value is set to false
 

Further I updated "booltest.py" to test type and print more info

print "Before conversion"
print "class :" + ip_bool.class.name
print "value " + str(ip_bool)
 
print "ip_bool is not True # " + str(ip_bool is not True)
print "ip_bool is not False # " + str(ip_bool is not False)
 
ip_bool1 = bool(ip_bool)
print "\nAfter conversion"
print "class :" + ip_bool1.class.name
print "value " + str(ip_bool1)
 
print "ip_bool is not True # " + str(ip_bool1 is not True)

print "ip_bool is not False # " + str(ip_bool1 is not False)

 
and it yields

 

Before conversion
class :bool
value False
ip_bool is not True # True
ip_bool is not False # True
 
After conversion
class :bool
value False
ip_bool is not True # True

ip_bool is not False # False

 
Thus passing a bool value from scripting libraries malfunctions

comments

bhadra wrote Oct 17, 2012 at 8:13 AM

is compares identity. None is not identical to True or False. So "ip_bool is not True" will evaluate to True and "ip_bool is not False" will evaluate to True. the standard Python function bool evaluates a Boolean expression.

[Reference: http://stackoverflow.com/questions/5119709/python-true-false]

So bool value conversion does not malfunction in IronPython.

I suggest that you close the issue.

SriharshaVardhan wrote Oct 28, 2012 at 6:30 PM

If ip_bool is none then I would expect ip_bool.class.name not to return the type as class :bool