sgzwiz / brython

Automatically exported from code.google.com/p/brython
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

Bad expression generation for boolean expression #37

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Code:
x = True
y = False
res = x and not y
print("res", res)

o = instance()
o.res = res
print("o.res 1", o.res)

o.res = (x and not y)
print("o.res 2", o.res)

o.res = x and not y
print("o.res 3", o.res)

Result:
res True
o.res 1 True
o.res 2 True

and following error in browser console:
--
ExecutionError: o.__setattr__(...) is not a function
module '__main__' line 13
o.res = x and not y @ http://www.brython.info/py_utils.js:36

When looking at generated javascript code:

res =$test_expr($test_item(x)&&$test_item($not(y)))
=> OK

o.__setattr__('res',$tuple($test_expr($test_item(x)&&$test_item($not(y)))))
=> STRANGE, since it is not a tuple,
   in python parenthesis do not generate a tuple,
   but the coma does
>>> x = 1, 2
>>> type(x)
<class 'tuple'>
>>> x = 1
>>> type(x)
<class 'int'>

o.__setattr__('res',$test_expr)($test_item(x)&&$test_item($not(y)))
=> WRONG, $test_expr is not applied to anything

Original issue reported on code.google.com by pedro.ro...@gmail.com on 5 Jan 2013 at 4:15

GoogleCodeExporter commented 9 years ago
Fixed in rev #341 : the type of the token added for $test_expr was wrong 
('code' instead of 'id') so the expression found at the right side of the 
equality sign stopped at $test_expr instead of covering the whole expression

Original comment by pierre.q...@gmail.com on 6 Jan 2013 at 8:24