Skip to content

Commit dd99d48

Browse files
Merge pull request #111 from pyscript/pyodide-literal-map-transform
Fixed Pyodide transform w/ LiteralMap
2 parents 00532f1 + ef50ee5 commit dd99d48

File tree

5 files changed

+22
-13
lines changed

5 files changed

+22
-13
lines changed

docs/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/interpreter/pyodide.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { create } from 'gc-hook';
33
import { RUNNING_IN_WORKER, fetchFiles, fetchJSModules, fetchPaths, writeFile } from './_utils.js';
44
import { getFormat, loader, registerJSModule, run, runAsync, runEvent } from './_python.js';
55
import { stdio } from './_io.js';
6+
import { isArray } from '../utils.js';
67

78
const type = 'pyodide';
89
const toJsOptions = { dict_converter: Object.fromEntries };
@@ -101,11 +102,7 @@ export default {
101102
run: overrideMethod(run),
102103
runAsync: overrideMethod(runAsync),
103104
runEvent: overrideMethod(runEvent),
104-
transform: ({ ffi: { PyProxy } }, value) => (
105-
value instanceof PyProxy ?
106-
value.toJs(toJsOptions) :
107-
value
108-
),
105+
transform: (interpreter, value) => transform.call(interpreter, value),
109106
writeFile: (interpreter, path, buffer, url) => {
110107
const format = getFormat(path, url);
111108
if (format) {
@@ -118,6 +115,18 @@ export default {
118115
},
119116
};
120117

118+
function transform(value) {
119+
const { ffi: { PyProxy } } = this;
120+
if (value && typeof value === 'object') {
121+
if (value instanceof PyProxy) return value.toJs(toJsOptions);
122+
// I believe this case is for LiteralMap which is not a PyProxy
123+
// and yet it needs to be re-converted to something useful.
124+
if (value instanceof Map) return new Map([...value.entries()]);
125+
if (isArray(value)) return value.map(transform, this);
126+
}
127+
return value;
128+
}
129+
121130
// exposed utility to import packages via polyscript.lazy_py_modules
122131
async function importPackages(packages) {
123132
await this.loadPackage('micropip');

package-lock.json

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

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@
7878
"@webreflection/idb-map": "^0.3.1",
7979
"basic-devtools": "^0.1.6",
8080
"codedent": "^0.1.2",
81-
"coincident": "^2.0.0",
81+
"coincident": "^2.0.1",
8282
"gc-hook": "^0.3.1",
8383
"html-escaper": "^3.0.3",
8484
"proxy-target": "^3.0.2",
8585
"sticky-module": "^0.1.1",
8686
"to-json-callback": "^0.1.1"
8787
},
8888
"worker": {
89-
"blob": "sha256-1s+d/z97T1TW7Z1FKqUH9XkdwJnOr2YgB5K73a94okA="
89+
"blob": "sha256-8aAxB/a1uoulnOjj6nNa2WkuNijTqucD8FzBxAW4XP4="
9090
}
9191
}

0 commit comments

Comments
 (0)