pyodide 0.20.0 → 0.20.1-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +31 -9
- package/pyodide.ts +31 -39
- package/api.ts +0 -495
- package/compat.ts +0 -146
- package/error_handling.gen.ts +0 -335
- package/index.d.ts +0 -1
- package/index.test-d.ts +0 -167
- package/load-package.ts +0 -414
- package/module.ts +0 -117
- package/pyproxy.gen.ts +0 -1507
- package/rollup.config.js +0 -43
- package/test/conftest.js +0 -7
- package/test/filesystem.test.js +0 -12
- package/test/module.test.js +0 -10
- package/test/pyodide.test.mjs +0 -26
- package/tsconfig.json +0 -15
package/error_handling.gen.ts
DELETED
|
@@ -1,335 +0,0 @@
|
|
|
1
|
-
import ErrorStackParser from "error-stack-parser";
|
|
2
|
-
import { Module, API, Hiwire, Tests } from "./module.js";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Dump the Python traceback to the browser console.
|
|
6
|
-
*
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
API.dump_traceback = function () {
|
|
10
|
-
const fd_stdout = 1;
|
|
11
|
-
Module.__Py_DumpTraceback(fd_stdout, Module._PyGILState_GetThisThreadState());
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function ensureCaughtObjectIsError(e: any) {
|
|
15
|
-
if (typeof e === "string") {
|
|
16
|
-
// Sometimes emscripten throws a raw string...
|
|
17
|
-
e = new Error(e);
|
|
18
|
-
} else if (
|
|
19
|
-
typeof e !== "object" ||
|
|
20
|
-
e === null ||
|
|
21
|
-
typeof e.stack !== "string" ||
|
|
22
|
-
typeof e.message !== "string"
|
|
23
|
-
) {
|
|
24
|
-
// We caught something really weird. Be brave!
|
|
25
|
-
let msg = `A value of type ${typeof e} with tag ${Object.prototype.toString.call(
|
|
26
|
-
e
|
|
27
|
-
)} was thrown as an error!`;
|
|
28
|
-
try {
|
|
29
|
-
msg += `\nString interpolation of the thrown value gives """${e}""".`;
|
|
30
|
-
} catch (e) {
|
|
31
|
-
msg += `\nString interpolation of the thrown value fails.`;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
msg += `\nThe thrown value's toString method returns """${e.toString()}""".`;
|
|
35
|
-
} catch (e) {
|
|
36
|
-
msg += `\nThe thrown value's toString method fails.`;
|
|
37
|
-
}
|
|
38
|
-
e = new Error(msg);
|
|
39
|
-
}
|
|
40
|
-
// Post conditions:
|
|
41
|
-
// 1. typeof e is object
|
|
42
|
-
// 2. hiwire_is_error(e) returns true
|
|
43
|
-
return e;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
let fatal_error_occurred = false;
|
|
47
|
-
/**
|
|
48
|
-
* Signal a fatal error.
|
|
49
|
-
*
|
|
50
|
-
* Dumps the Python traceback, shows a JavaScript traceback, and prints a clear
|
|
51
|
-
* message indicating a fatal error. It then dummies out the public API so that
|
|
52
|
-
* further attempts to use Pyodide will clearly indicate that Pyodide has failed
|
|
53
|
-
* and can no longer be used. pyodide._module is left accessible, and it is
|
|
54
|
-
* possible to continue using Pyodide for debugging purposes if desired.
|
|
55
|
-
*
|
|
56
|
-
* @argument e {Error} The cause of the fatal error.
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
API.fatal_error = function (e: any) {
|
|
60
|
-
if (e && e.pyodide_fatal_error) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (fatal_error_occurred) {
|
|
64
|
-
console.error("Recursive call to fatal_error. Inner error was:");
|
|
65
|
-
console.error(e);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
if (typeof e === "number") {
|
|
69
|
-
// Hopefully a C++ exception? Have to do some conversion work.
|
|
70
|
-
e = convertCppException(e);
|
|
71
|
-
} else {
|
|
72
|
-
e = ensureCaughtObjectIsError(e);
|
|
73
|
-
}
|
|
74
|
-
// Mark e so we know not to handle it later in EM_JS wrappers
|
|
75
|
-
e.pyodide_fatal_error = true;
|
|
76
|
-
fatal_error_occurred = true;
|
|
77
|
-
console.error(
|
|
78
|
-
"Pyodide has suffered a fatal error. Please report this to the Pyodide maintainers."
|
|
79
|
-
);
|
|
80
|
-
console.error("The cause of the fatal error was:");
|
|
81
|
-
if (API.inTestHoist) {
|
|
82
|
-
// Test hoist won't print the error object in a useful way so convert it to
|
|
83
|
-
// string.
|
|
84
|
-
console.error(e.toString());
|
|
85
|
-
console.error(e.stack);
|
|
86
|
-
} else {
|
|
87
|
-
console.error(e);
|
|
88
|
-
}
|
|
89
|
-
try {
|
|
90
|
-
API.dump_traceback();
|
|
91
|
-
for (let key of Object.keys(API.public_api)) {
|
|
92
|
-
if (key.startsWith("_") || key === "version") {
|
|
93
|
-
continue;
|
|
94
|
-
}
|
|
95
|
-
Object.defineProperty(API.public_api, key, {
|
|
96
|
-
enumerable: true,
|
|
97
|
-
configurable: true,
|
|
98
|
-
get: () => {
|
|
99
|
-
throw new Error(
|
|
100
|
-
"Pyodide already fatally failed and can no longer be used."
|
|
101
|
-
);
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
if (API.on_fatal) {
|
|
106
|
-
API.on_fatal(e);
|
|
107
|
-
}
|
|
108
|
-
} catch (err2) {
|
|
109
|
-
console.error("Another error occurred while handling the fatal error:");
|
|
110
|
-
console.error(err2);
|
|
111
|
-
}
|
|
112
|
-
throw e;
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
class CppException extends Error {
|
|
116
|
-
ty: string;
|
|
117
|
-
constructor(ty: string, msg: string) {
|
|
118
|
-
super(msg);
|
|
119
|
-
this.ty = ty;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
Object.defineProperty(CppException.prototype, "name", {
|
|
123
|
-
get() {
|
|
124
|
-
return `${this.constructor.name} ${this.ty}`;
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
*
|
|
130
|
-
* Return the type name, whether the pointer inherits from exception, and the
|
|
131
|
-
* vtable pointer for the type.
|
|
132
|
-
*
|
|
133
|
-
* This code is based on imitating:
|
|
134
|
-
* 1. the implementation of __cxa_find_matching_catch
|
|
135
|
-
* 2. the disassembly from:
|
|
136
|
-
* ```C++
|
|
137
|
-
* try {
|
|
138
|
-
* ...
|
|
139
|
-
* } catch(exception e){
|
|
140
|
-
* ...
|
|
141
|
-
* }
|
|
142
|
-
*
|
|
143
|
-
* @param ptr
|
|
144
|
-
* @returns
|
|
145
|
-
* exc_type_name : the type name of the exception, as would be reported by
|
|
146
|
-
* `typeid(type).name()` but also demangled.
|
|
147
|
-
*
|
|
148
|
-
* is_exception_subclass : true if the object is a subclass of exception. In
|
|
149
|
-
* this case we will use `exc.what()` to get an error message.
|
|
150
|
-
*
|
|
151
|
-
* adjusted_ptr : The adjusted vtable pointer for the exception to use to invoke
|
|
152
|
-
* exc.what().
|
|
153
|
-
*
|
|
154
|
-
* @private
|
|
155
|
-
*/
|
|
156
|
-
function cppExceptionInfo(ptr: number): [string, boolean, number] {
|
|
157
|
-
const base_exception_type = Module._exc_type();
|
|
158
|
-
const ei = new Module.ExceptionInfo(ptr);
|
|
159
|
-
const caught_exception_type = ei.get_type();
|
|
160
|
-
const stackTop = Module.stackSave();
|
|
161
|
-
const exceptionThrowBuf = Module.stackAlloc(4);
|
|
162
|
-
Module.HEAP32[exceptionThrowBuf / 4] = ptr;
|
|
163
|
-
const exc_type_name = Module.demangle(
|
|
164
|
-
Module.UTF8ToString(Module._exc_typename(caught_exception_type))
|
|
165
|
-
);
|
|
166
|
-
const is_exception_subclass = !!Module.___cxa_can_catch(
|
|
167
|
-
base_exception_type,
|
|
168
|
-
caught_exception_type,
|
|
169
|
-
exceptionThrowBuf
|
|
170
|
-
);
|
|
171
|
-
const adjusted_ptr = Module.HEAP32[exceptionThrowBuf / 4];
|
|
172
|
-
Module.stackRestore(stackTop);
|
|
173
|
-
return [exc_type_name, is_exception_subclass, adjusted_ptr];
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function convertCppException(ptr: number): CppException {
|
|
177
|
-
const [exc_type_name, is_exception_subclass, adjusted_ptr] =
|
|
178
|
-
cppExceptionInfo(ptr);
|
|
179
|
-
let msg;
|
|
180
|
-
if (is_exception_subclass) {
|
|
181
|
-
// If the ptr inherits from exception, we can use exception.what() to
|
|
182
|
-
// generate a message
|
|
183
|
-
const msgPtr = Module._exc_what(adjusted_ptr);
|
|
184
|
-
msg = Module.UTF8ToString(msgPtr);
|
|
185
|
-
} else {
|
|
186
|
-
msg = `The exception is an object of type ${exc_type_name} at address ${ptr} which does not inherit from std::exception`;
|
|
187
|
-
}
|
|
188
|
-
return new CppException(exc_type_name, msg);
|
|
189
|
-
}
|
|
190
|
-
// Expose for testing
|
|
191
|
-
Tests.convertCppException = convertCppException;
|
|
192
|
-
|
|
193
|
-
function isPyodideFrame(frame: ErrorStackParser.StackFrame): boolean {
|
|
194
|
-
const fileName = frame.fileName || "";
|
|
195
|
-
if (fileName.includes("pyodide.asm")) {
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
if (fileName.includes("wasm-function")) {
|
|
199
|
-
return true;
|
|
200
|
-
}
|
|
201
|
-
if (!fileName.includes("pyodide.js")) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
let funcName = frame.functionName || "";
|
|
205
|
-
if (funcName.startsWith("Object.")) {
|
|
206
|
-
funcName = funcName.slice("Object.".length);
|
|
207
|
-
}
|
|
208
|
-
if (funcName in API.public_api && funcName !== "PythonError") {
|
|
209
|
-
frame.functionName = funcName;
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
return true;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function isErrorStart(frame: ErrorStackParser.StackFrame): boolean {
|
|
216
|
-
if (!isPyodideFrame(frame)) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
const funcName = frame.functionName;
|
|
220
|
-
return funcName === "PythonError" || funcName === "new_error";
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
Module.handle_js_error = function (e: any) {
|
|
224
|
-
if (e && e.pyodide_fatal_error) {
|
|
225
|
-
throw e;
|
|
226
|
-
}
|
|
227
|
-
if (e instanceof Module._PropagatePythonError) {
|
|
228
|
-
// Python error indicator is already set in this case. If this branch is
|
|
229
|
-
// not taken, Python error indicator should be unset, and we have to set
|
|
230
|
-
// it. In this case we don't want to tamper with the traceback.
|
|
231
|
-
return;
|
|
232
|
-
}
|
|
233
|
-
let restored_error = false;
|
|
234
|
-
if (e instanceof API.PythonError) {
|
|
235
|
-
// Try to restore the original Python exception.
|
|
236
|
-
restored_error = Module._restore_sys_last_exception(e.__error_address);
|
|
237
|
-
}
|
|
238
|
-
let stack: any;
|
|
239
|
-
let weirdCatch;
|
|
240
|
-
try {
|
|
241
|
-
stack = ErrorStackParser.parse(e);
|
|
242
|
-
} catch (_) {
|
|
243
|
-
weirdCatch = true;
|
|
244
|
-
}
|
|
245
|
-
if (weirdCatch) {
|
|
246
|
-
e = ensureCaughtObjectIsError(e);
|
|
247
|
-
}
|
|
248
|
-
if (!restored_error) {
|
|
249
|
-
// Wrap the JavaScript error
|
|
250
|
-
let eidx = Hiwire.new_value(e);
|
|
251
|
-
let err = Module._JsProxy_create(eidx);
|
|
252
|
-
Module._set_error(err);
|
|
253
|
-
Module._Py_DecRef(err);
|
|
254
|
-
Hiwire.decref(eidx);
|
|
255
|
-
}
|
|
256
|
-
if (weirdCatch) {
|
|
257
|
-
// In this case we have no stack frames so we can quit
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
if (isErrorStart(stack[0])) {
|
|
261
|
-
while (isPyodideFrame(stack[0])) {
|
|
262
|
-
stack.shift();
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
// Add the Javascript stack frames to the Python traceback
|
|
266
|
-
for (const frame of stack) {
|
|
267
|
-
if (isPyodideFrame(frame)) {
|
|
268
|
-
break;
|
|
269
|
-
}
|
|
270
|
-
const funcnameAddr = Module.stringToNewUTF8(frame.functionName || "???");
|
|
271
|
-
const fileNameAddr = Module.stringToNewUTF8(frame.fileName || "???.js");
|
|
272
|
-
Module.__PyTraceback_Add(funcnameAddr, fileNameAddr, frame.lineNumber);
|
|
273
|
-
Module._free(funcnameAddr);
|
|
274
|
-
Module._free(fileNameAddr);
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* A JavaScript error caused by a Python exception.
|
|
280
|
-
*
|
|
281
|
-
* In order to reduce the risk of large memory leaks, the ``PythonError``
|
|
282
|
-
* contains no reference to the Python exception that caused it. You can find
|
|
283
|
-
* the actual Python exception that caused this error as `sys.last_value
|
|
284
|
-
* <https://docs.python.org/3/library/sys.html#sys.last_value>`_.
|
|
285
|
-
*
|
|
286
|
-
* See :ref:`type-translations-errors` for more information.
|
|
287
|
-
*
|
|
288
|
-
* .. admonition:: Avoid Stack Frames
|
|
289
|
-
* :class: warning
|
|
290
|
-
*
|
|
291
|
-
* If you make a :any:`PyProxy` of ``sys.last_value``, you should be
|
|
292
|
-
* especially careful to :any:`destroy() <PyProxy.destroy>` it when you are
|
|
293
|
-
* done. You may leak a large amount of memory including the local
|
|
294
|
-
* variables of all the stack frames in the traceback if you don't. The
|
|
295
|
-
* easiest way is to only handle the exception in Python.
|
|
296
|
-
*/
|
|
297
|
-
export class PythonError extends Error {
|
|
298
|
-
/** The address of the error we are wrapping. We may later compare this
|
|
299
|
-
* against sys.last_value.
|
|
300
|
-
* WARNING: we don't own a reference to this pointer, dereferencing it
|
|
301
|
-
* may be a use-after-free error!
|
|
302
|
-
* @private
|
|
303
|
-
*/
|
|
304
|
-
__error_address: number;
|
|
305
|
-
|
|
306
|
-
constructor(message: string, error_address: number) {
|
|
307
|
-
const oldLimit = Error.stackTraceLimit;
|
|
308
|
-
Error.stackTraceLimit = Infinity;
|
|
309
|
-
super(message);
|
|
310
|
-
Error.stackTraceLimit = oldLimit;
|
|
311
|
-
this.__error_address = error_address;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
Object.defineProperty(PythonError.prototype, "name", {
|
|
315
|
-
value: PythonError.name,
|
|
316
|
-
});
|
|
317
|
-
API.PythonError = PythonError;
|
|
318
|
-
// A special marker. If we call a CPython API from an EM_JS function and the
|
|
319
|
-
// CPython API sets an error, we might want to return an error status back to
|
|
320
|
-
// C keeping the current Python error flag. This signals to the EM_JS wrappers
|
|
321
|
-
// that the Python error flag is set and to leave it alone and return the
|
|
322
|
-
// appropriate error value (either NULL or -1).
|
|
323
|
-
class _PropagatePythonError extends Error {
|
|
324
|
-
constructor() {
|
|
325
|
-
API.fail_test = true;
|
|
326
|
-
super(
|
|
327
|
-
"If you are seeing this message, an internal Pyodide error has " +
|
|
328
|
-
"occurred. Please report it to the Pyodide maintainers."
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
Object.defineProperty(_PropagatePythonError.prototype, "name", {
|
|
333
|
-
value: _PropagatePythonError.name,
|
|
334
|
-
});
|
|
335
|
-
Module._PropagatePythonError = _PropagatePythonError;
|
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// This file is just needed to make "npx tsd" work (otherwise it will quit with an error).
|
package/index.test-d.ts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import { expectType, expectAssignable } from "tsd";
|
|
2
|
-
import {
|
|
3
|
-
loadPyodide,
|
|
4
|
-
PyProxy,
|
|
5
|
-
PyProxyWithLength,
|
|
6
|
-
PyProxyWithGet,
|
|
7
|
-
PyProxyWithSet,
|
|
8
|
-
PyProxyWithHas,
|
|
9
|
-
PyProxyIterable,
|
|
10
|
-
PyProxyIterator,
|
|
11
|
-
PyProxyAwaitable,
|
|
12
|
-
PyProxyBuffer,
|
|
13
|
-
PyProxyCallable,
|
|
14
|
-
PyBuffer,
|
|
15
|
-
TypedArray,
|
|
16
|
-
} from "./pyodide";
|
|
17
|
-
|
|
18
|
-
async function main() {
|
|
19
|
-
let pyodide = await loadPyodide();
|
|
20
|
-
expectType<Promise<typeof pyodide>>(loadPyodide({ indexURL: "blah" }));
|
|
21
|
-
expectType<Promise<typeof pyodide>>(loadPyodide({ fullStdLib: true }));
|
|
22
|
-
|
|
23
|
-
expectType<Promise<typeof pyodide>>(
|
|
24
|
-
loadPyodide({
|
|
25
|
-
indexURL: "blah",
|
|
26
|
-
fullStdLib: true,
|
|
27
|
-
stdin: () => "a string",
|
|
28
|
-
stdout: (x: string) => {},
|
|
29
|
-
stderr: (err: string) => {},
|
|
30
|
-
})
|
|
31
|
-
);
|
|
32
|
-
|
|
33
|
-
expectType<PyProxy>(pyodide.globals);
|
|
34
|
-
|
|
35
|
-
let x: any;
|
|
36
|
-
expectType<boolean>(pyodide.isPyProxy(x));
|
|
37
|
-
if (pyodide.isPyProxy(x)) {
|
|
38
|
-
expectType<PyProxy>(x);
|
|
39
|
-
} else {
|
|
40
|
-
expectType<any>(x);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let px: PyProxy = <PyProxy>{};
|
|
44
|
-
|
|
45
|
-
expectType<any>(pyodide.runPython("1+1"));
|
|
46
|
-
expectType<any>(pyodide.runPython("1+1", { globals: px }));
|
|
47
|
-
expectType<Promise<any>>(pyodide.runPythonAsync("1+1"));
|
|
48
|
-
expectType<Promise<any>>(pyodide.runPythonAsync("1+1", { globals: px }));
|
|
49
|
-
|
|
50
|
-
expectType<Promise<void>>(pyodide.loadPackagesFromImports("import some_pkg"));
|
|
51
|
-
expectType<Promise<void>>(
|
|
52
|
-
pyodide.loadPackagesFromImports("import some_pkg", (x: any) =>
|
|
53
|
-
console.log(x)
|
|
54
|
-
)
|
|
55
|
-
);
|
|
56
|
-
expectType<Promise<void>>(
|
|
57
|
-
pyodide.loadPackagesFromImports(
|
|
58
|
-
"import some_pkg",
|
|
59
|
-
(x: any) => console.log(x),
|
|
60
|
-
(x: any) => console.warn(x)
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
expectType<Promise<void>>(pyodide.loadPackage("blah"));
|
|
65
|
-
expectType<Promise<void>>(pyodide.loadPackage(["blah", "blah2"]));
|
|
66
|
-
expectType<Promise<void>>(
|
|
67
|
-
pyodide.loadPackage("blah", (x: any) => console.log(x))
|
|
68
|
-
);
|
|
69
|
-
expectType<Promise<void>>(
|
|
70
|
-
pyodide.loadPackage(
|
|
71
|
-
["blah", "blah2"],
|
|
72
|
-
(x: any) => console.log(x),
|
|
73
|
-
(x: any) => console.warn(x)
|
|
74
|
-
)
|
|
75
|
-
);
|
|
76
|
-
expectType<Promise<void>>(pyodide.loadPackage(px));
|
|
77
|
-
|
|
78
|
-
expectType<PyProxy>(pyodide.pyodide_py);
|
|
79
|
-
expectType<void>(pyodide.registerJsModule("blah", { a: 7 }));
|
|
80
|
-
expectType<void>(pyodide.unregisterJsModule("blah"));
|
|
81
|
-
|
|
82
|
-
pyodide.setInterruptBuffer(new Int32Array(1));
|
|
83
|
-
expectType<any>(pyodide.toPy({}));
|
|
84
|
-
expectType<string>(pyodide.version);
|
|
85
|
-
|
|
86
|
-
expectType<any>(px.x);
|
|
87
|
-
expectType<PyProxy>(px.copy());
|
|
88
|
-
expectType<void>(px.destroy("blah"));
|
|
89
|
-
expectType<void>(px.destroy());
|
|
90
|
-
expectType<any>(px.toJs());
|
|
91
|
-
expectType<any>(px.toJs({}));
|
|
92
|
-
expectType<any>(px.toJs({ depth: 10 }));
|
|
93
|
-
expectType<any>(px.toJs({ create_pyproxies: false }));
|
|
94
|
-
expectType<any>(px.toJs({ create_pyproxies: true }));
|
|
95
|
-
expectType<any>(px.toJs({ pyproxies: [] }));
|
|
96
|
-
expectType<string>(px.toString());
|
|
97
|
-
expectType<string>(px.type);
|
|
98
|
-
|
|
99
|
-
if (px.supportsGet()) {
|
|
100
|
-
expectType<PyProxyWithGet>(px);
|
|
101
|
-
expectType<(x: any) => any>(px.get);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
if (px.supportsHas()) {
|
|
105
|
-
expectType<PyProxyWithHas>(px);
|
|
106
|
-
expectType<(x: any) => boolean>(px.has);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (px.supportsLength()) {
|
|
110
|
-
expectType<PyProxyWithLength>(px);
|
|
111
|
-
expectType<number>(px.length);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (px.supportsSet()) {
|
|
115
|
-
expectType<PyProxyWithSet>(px);
|
|
116
|
-
expectType<(x: any, y: any) => void>(px.set);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (px.isAwaitable()) {
|
|
120
|
-
expectType<PyProxyAwaitable>(px);
|
|
121
|
-
expectType<any>(await px);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (px.isBuffer()) {
|
|
125
|
-
expectType<PyProxyBuffer>(px);
|
|
126
|
-
let buf = px.getBuffer();
|
|
127
|
-
expectType<PyBuffer>(buf);
|
|
128
|
-
expectType<boolean>(buf.c_contiguous);
|
|
129
|
-
expectType<TypedArray>(buf.data);
|
|
130
|
-
expectType<boolean>(buf.f_contiguous);
|
|
131
|
-
expectType<string>(buf.format);
|
|
132
|
-
expectType<number>(buf.itemsize);
|
|
133
|
-
expectType<number>(buf.nbytes);
|
|
134
|
-
expectType<number>(buf.ndim);
|
|
135
|
-
expectType<number>(buf.offset);
|
|
136
|
-
expectType<boolean>(buf.readonly);
|
|
137
|
-
expectType<() => void>(buf.release);
|
|
138
|
-
expectType<number[]>(buf.shape);
|
|
139
|
-
expectType<number[]>(buf.strides);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (px.isCallable()) {
|
|
143
|
-
expectType<PyProxyCallable>(px);
|
|
144
|
-
expectType<any>(px(1, 2, 3));
|
|
145
|
-
expectAssignable<(...args: any[]) => any>(px);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (px.isIterable()) {
|
|
149
|
-
expectType<PyProxyIterable>(px);
|
|
150
|
-
for (let x of px) {
|
|
151
|
-
expectType<any>(x);
|
|
152
|
-
}
|
|
153
|
-
let it = px[Symbol.iterator]();
|
|
154
|
-
expectAssignable<{ done?: any; value: any }>(it.next());
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (px.isIterator()) {
|
|
158
|
-
expectType<PyProxyIterator>(px);
|
|
159
|
-
expectAssignable<{ done?: any; value: any }>(px.next());
|
|
160
|
-
expectAssignable<{ done?: any; value: any }>(px.next(22));
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
pyodide.unpackArchive(new Uint8Array(40), "tar");
|
|
164
|
-
pyodide.unpackArchive(new Uint8Array(40), "tar", {
|
|
165
|
-
extractDir: "/some/path",
|
|
166
|
-
});
|
|
167
|
-
}
|