Skip to content

Updated Polyscript to its latest #2364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
407 changes: 197 additions & 210 deletions core/package-lock.json

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pyscript/core",
"version": "0.6.65",
"version": "0.6.70",
"type": "module",
"description": "PyScript",
"module": "./index.js",
Expand Down Expand Up @@ -42,7 +42,7 @@
},
"scripts": {
"server": "echo \"➡️ TESTS @ $(tput bold)http://localhost:8080/tests/$(tput sgr0)\"; npx static-handler --coi .",
"build": "export ESLINT_USE_FLAT_CONFIG=true;npm run build:3rd-party && npm run build:stdlib && npm run build:plugins && npm run build:core && npm run build:tests-index && if [ -z \"$NO_MIN\" ]; then eslint src/ && npm run ts && npm run test:integration; fi",
"build": "export ESLINT_USE_FLAT_CONFIG=true;npm run build:3rd-party && npm run build:stdlib && npm run build:plugins && npm run build:core && npm run build:tests-index && if [ -z \"$NO_MIN\" ]; then eslint src/ && npm run test:integration; fi",
"build:core": "rm -rf dist && rollup --config rollup/core.config.js && cp src/3rd-party/*.css dist/",
"build:flatted": "node rollup/flatted.cjs",
"build:plugins": "node rollup/plugins.cjs",
Expand Down Expand Up @@ -70,7 +70,7 @@
"@webreflection/utils": "^0.1.1",
"add-promise-listener": "^0.1.3",
"basic-devtools": "^0.1.6",
"polyscript": "^0.18.3",
"polyscript": "^0.18.9",
"sticky-module": "^0.1.1",
"to-json-callback": "^0.1.1",
"type-checked-collections": "^0.1.7"
Expand All @@ -80,27 +80,27 @@
"@codemirror/lang-python": "^6.2.1",
"@codemirror/language": "^6.11.2",
"@codemirror/state": "^6.5.2",
"@codemirror/view": "^6.38.0",
"@playwright/test": "^1.54.0",
"@codemirror/view": "^6.38.1",
"@playwright/test": "^1.54.2",
"@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-terser": "^0.4.4",
"@webreflection/toml-j0.4": "^1.1.4",
"@xterm/addon-fit": "^0.10.0",
"@xterm/addon-web-links": "^0.11.0",
"@xterm/xterm": "^5.5.0",
"bun": "^1.2.18",
"bun": "^1.2.19",
"chokidar": "^4.0.3",
"codedent": "^0.1.2",
"codemirror": "^6.0.2",
"eslint": "^9.30.1",
"eslint": "^9.32.0",
"flatted": "^3.3.3",
"rollup": "^4.44.2",
"rollup": "^4.46.2",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-string": "^3.0.0",
"static-handler": "^0.5.3",
"string-width": "^7.2.0",
"typescript": "^5.8.3",
"typescript": "^5.9.2",
"xterm-readline": "^1.1.2"
},
"repository": {
Expand Down
8 changes: 4 additions & 4 deletions core/src/stdlib/pyscript.js

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions core/src/stdlib/pyscript/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re

from pyscript.magic_js import current_target, document, window
from pyscript.ffi import is_none

_MIME_METHODS = {
"savefig": "image/png",
Expand Down Expand Up @@ -105,13 +106,13 @@ def _format_mime(obj):
else:
output = _eval_formatter(obj, method)

if output is None:
if is_none(output):
continue
if mime_type not in _MIME_RENDERERS:
not_available.append(mime_type)
continue
break
if output is None:
if is_none(output):
if not_available:
window.console.warn(
f"Rendered object requested unavailable MIME renderers: {not_available}"
Expand All @@ -135,7 +136,7 @@ def _write(element, value, append=False):
element.append(out_element)
else:
out_element = element.lastElementChild
if out_element is None:
if is_none(out_element):
out_element = element

if mime_type in ("application/javascript", "text/html"):
Expand All @@ -146,7 +147,7 @@ def _write(element, value, append=False):


def display(*values, target=None, append=True):
if target is None:
if is_none(target):
target = current_target()
elif not isinstance(target, str):
msg = f"target must be str or None, not {target.__class__.__name__}"
Expand All @@ -162,7 +163,7 @@ def display(*values, target=None, append=True):
element = document.getElementById(target)

# If target cannot be found on the page, a ValueError is raised
if element is None:
if is_none(element):
msg = f"Invalid selector with id={target}. Cannot be found in the page."
raise ValueError(msg)

Expand Down
6 changes: 6 additions & 0 deletions core/src/stdlib/pyscript/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
import js
from pyodide.ffi import create_proxy as _cp
from pyodide.ffi import to_js as _py_tjs
from pyodide.ffi import jsnull

from_entries = js.Object.fromEntries
is_none = lambda value: value is None or value is jsnull

def _tjs(value, **kw):
if not hasattr(kw, "dict_converter"):
Expand All @@ -13,6 +15,10 @@ def _tjs(value, **kw):
except:
from jsffi import create_proxy as _cp
from jsffi import to_js as _tjs
import js

jsnull = js.Object.getPrototypeOf(js.Object.prototype)
is_none = lambda value: value is None or value is jsnull

create_proxy = _cp
to_js = _tjs
Expand Down
3 changes: 2 additions & 1 deletion core/src/stdlib/pyscript/storage.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from polyscript import storage as _storage
from pyscript.flatted import parse as _parse
from pyscript.flatted import stringify as _stringify
from pyscript.ffi import is_none


# convert a Python value into an IndexedDB compatible entry
def _to_idb(value):
if value is None:
if is_none(value):
return _stringify(["null", 0])
if isinstance(value, (bool, float, int, str, list, dict, tuple)):
return _stringify(["generic", value])
Expand Down
12 changes: 7 additions & 5 deletions core/src/stdlib/pyscript/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# from __future__ import annotations # CAUTION: This is not supported in MicroPython.

from pyscript import document, when, Event # noqa: F401
from pyscript.ffi import create_proxy
from pyscript.ffi import create_proxy, is_none


def wrap_dom_element(dom_element):
Expand Down Expand Up @@ -68,8 +68,10 @@ def __init__(self, dom_element=None, classes=None, style=None, **kwargs):
If `dom_element` is None we are being called to *create* a new element.
Otherwise, we are being called to *wrap* an existing DOM element.
"""
self._dom_element = dom_element or document.createElement(
type(self).get_tag_name()
self._dom_element = (
document.createElement(type(self).get_tag_name())
if is_none(dom_element)
else dom_element
)

# HTML on_events attached to the element become pyscript.Event instances.
Expand Down Expand Up @@ -195,7 +197,7 @@ def classes(self):
@property
def parent(self):
"""Return the element's `parent `Element`."""
if self._dom_element.parentElement is None:
if is_none(self._dom_element.parentElement):
return None

return Element.wrap_dom_element(self._dom_element.parentElement)
Expand Down Expand Up @@ -1134,7 +1136,7 @@ def snap(
width = width if width is not None else self.videoWidth
height = height if height is not None else self.videoHeight

if to is None:
if is_none(to):
to = canvas(width=width, height=height)

elif isinstance(to, Element):
Expand Down
2 changes: 1 addition & 1 deletion core/types/core.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,5 @@ declare const exportedHooks: {
};
};
declare const exportedConfig: {};
declare const exportedWhenDefined: any;
declare const exportedWhenDefined: (type: string) => Promise<object>;
export { codemirror, stdlib, optional, inputFailure, TYPES, relative_url, exportedPyWorker as PyWorker, exportedMPWorker as MPWorker, exportedHooks as hooks, exportedConfig as config, exportedWhenDefined as whenDefined };
Loading