question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

None value is not coverted to null in JavaScript.

See original GitHub issue

I don’t know if this is a bug but I have code like this (that use jQuery Terminal library):

from browser import window, alert

def interpreter(command, term):
    term.echo(">>> " + command)

window.jQuery("body").terminal(interpreter)

and I have exception in JavaScript because None value returned by interpreter is a cycle that can’t be used in JSON.stringify because In jQuery Terminal the value returned by the function is processed and echoed in terminal (It can be a string or a promise). Is there a way to convert None to null or undefined to be used in JavaScript or return undefined/null from javascript?

I’ve fixed the issue by wrapping terminal function invocation and wrap interpreter with function that don’t return anything, but it would be nice if Brython convert None to null in python functions.

I’m using stable version from github.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
PierreQuentelcommented, Oct 30, 2017

In the commit referenced above I have added 2 new constants in built-in module javascript, called NULL and UNDEFINED, set to Javascript values null and undefined. They can be returned by a Brython function used by a Javascript library that handles these values.

I tried this code in a page with the Terminal library :

from browser import window
import javascript

def interpreter(command, term):
    term.echo(">>> " + command)
    return javascript.UNDEFINED

window.jQuery("body").terminal(interpreter)

I don’t know if the program does what is expected, but at least it doesn’t crash 😉

Does this help ?

0reactions
PierreQuentelcommented, Oct 30, 2017

As Jonathan said, it’s not possible for a function to know if it’s called from Brython or Javascript. And anyway, there must be a way to return either null or undefined (I saw that jQuery Terminal doesn’t handle these values the same way).

Can the issue be closed ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript Null does not convert to None - Stack Overflow
Generally, "null" items would be missing entirely, alternatively, they would have an empty value associated with them.
Read more >
null - JavaScript - MDN Web Docs - Mozilla
The null value represents the intentional absence of any object value. It is one of JavaScript's primitive values and is treated as falsy...
Read more >
How null is converted to Number in JavaScript? - Tutorialspoint
The Number() method in JavaScript is used to convert a value into a number. If the value is not convertible, then it will...
Read more >
Understanding Null Versus the Empty String
For example, any code inside the following conditional block will not execute because the value of varA (null) does not equals the value...
Read more >
DoubleConverter cannot convert from (null) - UiPath Forum
No it won't. Logically when field is empty the robot get the text as null, that's not a value to a variable, it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found