Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DerThorsten committed Mar 27, 2024
1 parent 2077bb0 commit e3aa1a1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
4 changes: 3 additions & 1 deletion examples/js_api_tour.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,12 @@ console.log(Array.from(js_map.values()))
const sum = pyjs.eval("sum([i for i in range(0,101)])")
sum

// %% [code]
// is_true is a plain javascript boolean
const is_true = pyjs.eval("sum([i for i in range(0,101)]) == 5050")
is_true

// %% [code]
// none will be undefined
let none = pyjs.eval('None')
console.log(none)
Expand All @@ -147,4 +149,4 @@ await asyncio.sleep(2)
sum([i for i in range(100)])
`
result = await pyjs.async_exec_eval(py_code)
console.log(result); // 4950
console.log(result);
22 changes: 2 additions & 20 deletions examples/py_api_tour.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
# %% [code]
import pyjs



# %% [markdown]
# # Accessing the the JavaScript global object
#
Expand All @@ -20,22 +18,8 @@
# %% [code]
pyjs.js.location.origin # equivalent to the javascript expression `location.origin` / `globalThis.location.origin`





# %% [markdown]
# # Create JavaScript functions on the fly
#
# To create a javascript fuction like the following
#
# .. code-block:: JavaScript
#
# my_function = function(a, b) {
# return a + b;
# }
#
# we can do the following:

# %% [code]
# define the function
Expand Down Expand Up @@ -66,6 +50,7 @@
py_dict = pyjs.to_py(js_nested_object)
py_dict

# %% [markdown]
# ### Custom converters
#
# Pyjs allows to register custom converters for specific javascript classes.
Expand Down Expand Up @@ -101,7 +86,6 @@ def rectangle_converter(js_val, depth, cache, converter_options):
assert isinstance(r, Rectangle)
assert r.height == 10
assert r.width == 20
# %%

# %% [markdown]
# ## Implicit conversion
Expand All @@ -120,6 +104,4 @@ def rectangle_converter(js_val, depth, cache, converter_options):
assert isinstance(js_function("hello", "world"), str)
assert isinstance(js_function(1, 2), int)
assert isinstance(js_function(1.5, 2.0), float)
assert isinstance(js_function(1.5, 2.5), int) # (!)

# %%
assert isinstance(js_function(1.5, 2.5), int) # (!)

0 comments on commit e3aa1a1

Please sign in to comment.