chrivers/pyjaco — Issue #8: False != false?
Author: buchuki
Created: 2012-01-03 20:06:02+00:00
State: open

As an outsider to pyjaco, I'd like to discuss my surprise that the boolean False in python does not map directly to the boolean false in javascript. I'm not necessarily requesting a change, but I'd like to understand the design decisions. The following python compiles to the javascript below it using the pyjs.py script I have written, which uses Compiler.append_string. I don't know if other compile methods behave differently? If so, why?

```python
#@JSVar("alert", "false")
@JSVar("alert")
def submit_add_form(ev):
alert('submitted')
return False
```

compiles to:
```
var submit_add_form = function() {
var __kwargs = __kwargs_get(arguments);
var __varargs = __varargs_get(arguments);
var $v3 = Array.prototype.slice.call(arguments).concat(js(__varargs));
var ev = ('ev' in __kwargs) ? __kwargs['ev'] : $v3[0];
delete __kwargs.ev
alert("submitted");
return False;
}
```

In this case, the False return is supposed to stop the propagation of the submit event to the form handler, the function is hooked up to the jquery submit function on a form. Because it is returning the py-builtins object False instead of the boolean false, the event propagation is NOT stopped as I would expect from this code.

Is this intended behavior, and if so, what is the best practice for dealing with situations like this? I have determined that I can return false without defining false and it works correctly. However, I don't feel this is optimal, as my original code is not valid python anymore.