Skip to content

Commit c3997ae

Browse files
committed
Updated Polyscript to its latest
1 parent 4d2a5c0 commit c3997ae

File tree

8 files changed

+161
-152
lines changed

8 files changed

+161
-152
lines changed

core/package-lock.json

Lines changed: 129 additions & 129 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pyscript/core",
3-
"version": "0.6.65",
3+
"version": "0.6.68",
44
"type": "module",
55
"description": "PyScript",
66
"module": "./index.js",
@@ -42,7 +42,7 @@
4242
},
4343
"scripts": {
4444
"server": "echo \"➡️ TESTS @ $(tput bold)http://localhost:8080/tests/$(tput sgr0)\"; npx static-handler --coi .",
45-
"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",
45+
"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",
4646
"build:core": "rm -rf dist && rollup --config rollup/core.config.js && cp src/3rd-party/*.css dist/",
4747
"build:flatted": "node rollup/flatted.cjs",
4848
"build:plugins": "node rollup/plugins.cjs",
@@ -70,7 +70,7 @@
7070
"@webreflection/utils": "^0.1.1",
7171
"add-promise-listener": "^0.1.3",
7272
"basic-devtools": "^0.1.6",
73-
"polyscript": "^0.18.5",
73+
"polyscript": "^0.18.9",
7474
"sticky-module": "^0.1.1",
7575
"to-json-callback": "^0.1.1",
7676
"type-checked-collections": "^0.1.7"
@@ -81,7 +81,7 @@
8181
"@codemirror/language": "^6.11.2",
8282
"@codemirror/state": "^6.5.2",
8383
"@codemirror/view": "^6.38.1",
84-
"@playwright/test": "^1.54.1",
84+
"@playwright/test": "^1.54.2",
8585
"@rollup/plugin-commonjs": "^28.0.6",
8686
"@rollup/plugin-node-resolve": "^16.0.1",
8787
"@rollup/plugin-terser": "^0.4.4",
@@ -93,14 +93,14 @@
9393
"chokidar": "^4.0.3",
9494
"codedent": "^0.1.2",
9595
"codemirror": "^6.0.2",
96-
"eslint": "^9.31.0",
96+
"eslint": "^9.32.0",
9797
"flatted": "^3.3.3",
98-
"rollup": "^4.45.1",
98+
"rollup": "^4.46.2",
9999
"rollup-plugin-postcss": "^4.0.2",
100100
"rollup-plugin-string": "^3.0.0",
101101
"static-handler": "^0.5.3",
102102
"string-width": "^7.2.0",
103-
"typescript": "^5.8.3",
103+
"typescript": "^5.9.2",
104104
"xterm-readline": "^1.1.2"
105105
},
106106
"repository": {

core/src/stdlib/pyscript.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/stdlib/pyscript/display.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55

66
from pyscript.magic_js import current_target, document, window
7+
from pyscript.ffi import is_null
78

89
_MIME_METHODS = {
910
"savefig": "image/png",
@@ -105,13 +106,13 @@ def _format_mime(obj):
105106
else:
106107
output = _eval_formatter(obj, method)
107108

108-
if output is None:
109+
if is_null(output):
109110
continue
110111
if mime_type not in _MIME_RENDERERS:
111112
not_available.append(mime_type)
112113
continue
113114
break
114-
if output is None:
115+
if is_null(output):
115116
if not_available:
116117
window.console.warn(
117118
f"Rendered object requested unavailable MIME renderers: {not_available}"
@@ -135,7 +136,7 @@ def _write(element, value, append=False):
135136
element.append(out_element)
136137
else:
137138
out_element = element.lastElementChild
138-
if out_element is None:
139+
if is_null(out_element):
139140
out_element = element
140141

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

147148

148149
def display(*values, target=None, append=True):
149-
if target is None:
150+
if is_null(target):
150151
target = current_target()
151152
elif not isinstance(target, str):
152153
msg = f"target must be str or None, not {target.__class__.__name__}"
@@ -162,7 +163,7 @@ def display(*values, target=None, append=True):
162163
element = document.getElementById(target)
163164

164165
# If target cannot be found on the page, a ValueError is raised
165-
if element is None:
166+
if is_null(element):
166167
msg = f"Invalid selector with id={target}. Cannot be found in the page."
167168
raise ValueError(msg)
168169

core/src/stdlib/pyscript/ffi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
import js
33
from pyodide.ffi import create_proxy as _cp
44
from pyodide.ffi import to_js as _py_tjs
5+
from pyodide.ffi import jsnull
56

67
from_entries = js.Object.fromEntries
8+
is_null = lambda value: value is None or value is jsnull
79

810
def _tjs(value, **kw):
911
if not hasattr(kw, "dict_converter"):
@@ -13,6 +15,9 @@ def _tjs(value, **kw):
1315
except:
1416
from jsffi import create_proxy as _cp
1517
from jsffi import to_js as _tjs
18+
import js
19+
jsnull = js.Object.getPrototypeOf(js.Object.prototype)
20+
is_null = lambda value: value is None or value is jsnull
1621

1722
create_proxy = _cp
1823
to_js = _tjs

core/src/stdlib/pyscript/storage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from polyscript import storage as _storage
22
from pyscript.flatted import parse as _parse
33
from pyscript.flatted import stringify as _stringify
4+
from pyscript.ffi import is_null
45

56

67
# convert a Python value into an IndexedDB compatible entry
78
def _to_idb(value):
8-
if value is None:
9+
if is_null(value):
910
return _stringify(["null", 0])
1011
if isinstance(value, (bool, float, int, str, list, dict, tuple)):
1112
return _stringify(["generic", value])

core/src/stdlib/pyscript/web.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# from __future__ import annotations # CAUTION: This is not supported in MicroPython.
77

88
from pyscript import document, when, Event # noqa: F401
9-
from pyscript.ffi import create_proxy
9+
from pyscript.ffi import create_proxy, is_null
1010

1111

1212
def wrap_dom_element(dom_element):
@@ -68,8 +68,10 @@ def __init__(self, dom_element=None, classes=None, style=None, **kwargs):
6868
If `dom_element` is None we are being called to *create* a new element.
6969
Otherwise, we are being called to *wrap* an existing DOM element.
7070
"""
71-
self._dom_element = dom_element or document.createElement(
72-
type(self).get_tag_name()
71+
self._dom_element = (
72+
document.createElement(type(self).get_tag_name())
73+
if is_null(dom_element)
74+
else dom_element
7375
)
7476

7577
# HTML on_events attached to the element become pyscript.Event instances.
@@ -195,7 +197,7 @@ def classes(self):
195197
@property
196198
def parent(self):
197199
"""Return the element's `parent `Element`."""
198-
if self._dom_element.parentElement is None:
200+
if is_null(self._dom_element.parentElement):
199201
return None
200202

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

1137-
if to is None:
1139+
if is_null(to):
11381140
to = canvas(width=width, height=height)
11391141

11401142
elif isinstance(to, Element):

core/types/core.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,5 @@ declare const exportedHooks: {
6363
};
6464
};
6565
declare const exportedConfig: {};
66-
declare const exportedWhenDefined: any;
66+
declare const exportedWhenDefined: (type: string) => Promise<object>;
6767
export { codemirror, stdlib, optional, inputFailure, TYPES, relative_url, exportedPyWorker as PyWorker, exportedMPWorker as MPWorker, exportedHooks as hooks, exportedConfig as config, exportedWhenDefined as whenDefined };

0 commit comments

Comments
 (0)