Brython not playing well with Opal.
See original GitHub issueI am trying to get Opal (Ruby for JS) to play well with Brython.
But for some reason if Opal is loaded before Brython, and i then try to import datetime, i get an error.
If i remove the script that loads Opal, the error goes away again.
Minimal example that has the error:
<!doctype html>
<html>
<head>
<script src="https://cdn.opalrb.com/opal/1.0.0/opal.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/brython@3.8.8/brython.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/brython@3.8.8/brython_stdlib.js"></script>
</head>
<body onload="brython(1)">
<script type="text/python">
import datetime
</script>
</body>
</html>
The error is:
Javascript exception: TypeError: Cannot read property 'length' of undefined
at Object.$B.$getattr (brython.js:6908)
at _is_dst3982 (eval at exec_module (brython.js:9272), <anonymous>:428:91)
at eval (eval at exec_module (brython.js:9272), <anonymous>:733:65)
at exec_module (brython.js:9272)
at t (brython.js:6570)
at s (brython.js:6574)
at Object.e.import_hooks (brython.js:13989)
at $B.$__import__ (brython.js:9428)
at Object.$B.$import (brython.js:9472)
at eval (eval at exec_module (brython.js:9272), <anonymous>:16:8)
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
[Idea] Compile Python code with Brython statically · Issue #1416
I have looked at code and even run it with debugger, but I did not get how to hook importing module with Brython...
Read more >Frequently asked questions - Brython documentation
Another reason why it is a not a good idea to precompile Brython is that the generated code is typically 10 times bigger...
Read more >Limitations of the "file" protocol - Brython documentation
With this protocol, it is always possible to import the modules in the standard library if the file brython_stdlib.js is loaded in the...
Read more >Testing and debugging - Brython documentation
Testing and debugging. Interactive test. The Brythons site, or its mirror available for download, include a console where you can test Python code....
Read more >module browser.aio - Brython documentation
It replaces the asyncio module in CPython standard library, which cannot work in the browser context: it uses blocking functions such as run()...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The latest commit changes an internal attribute
$value
used by Brython for instances of subclasses ofint
orfloat
to a more specific$brython_value
. Opal apparently sets the attribute$value
for numbers, which caused the incompatibility.@dkgof Interesting !
In Brython, the class of an object is usually determined by its attribute
__class__
but, for a reason that I don’t remember, the attribute$class
was used instead for a particular class (module), so this attribute$class
was tested in the function that gets an object’s class.Unfortunately, it seems that Opal sets an attribute
$class
to Javascript’sDate
objects…In the commit referenced above I have removed the use of
$class
in Brython, and your code now works. I leave the issue open for the moment, in case you find other incompatibilities.