Skip to content

Commit

Permalink
Fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 authored Sep 25, 2024
1 parent 0687808 commit 85edbac
Show file tree
Hide file tree
Showing 11 changed files with 69 additions and 60 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ jobs:

- name: Build package
working-directory: src/js
run: bun build pyodide.ts --outdir=dist --sourcemap=linked
run: |
mkdir -p generated
cp ../core/*.ts ./generated/
sed -i 's@../js/@../@g' ./generated/error_handling.ts
sed -i 's@from "types"@from "../types"@g' ./generated/pyproxy.ts
sed -i 's@from "pyodide-util"@from "../pyodide-util"@g' ./generated/pyproxy.ts
bun build pyodide.ts --outdir=dist --sourcemap=linked
- name: Upload artifacts
uses: actions/upload-artifact@v4
Expand Down
62 changes: 31 additions & 31 deletions src/core/pyproxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
declare var Tests: any;
declare var Module: any;

import { TypedArray } from "types";
import type { TypedArray } from "types";
import { warnOnce } from "pyodide-util";

// pyodide-skip
Expand Down Expand Up @@ -101,7 +101,7 @@ if (globalThis.FinalizationRegistry) {
// }
// });
} else {
Module.finalizationRegistry = { register() {}, unregister() {} };
Module.finalizationRegistry = { register() { }, unregister() { } };
// Module.bufferFinalizationRegistry = finalizationRegistry;
}

Expand All @@ -119,8 +119,8 @@ Module.enable_pyproxy_allocation_tracing = function () {
};
};
Module.disable_pyproxy_allocation_tracing = function () {
trace_pyproxy_alloc = function (proxy: any) {};
trace_pyproxy_dealloc = function (proxy: any) {};
trace_pyproxy_alloc = function (proxy: any) { };
trace_pyproxy_dealloc = function (proxy: any) { };
};
Module.disable_pyproxy_allocation_tracing();

Expand Down Expand Up @@ -236,7 +236,7 @@ function pyproxy_new(
// `setPrototypeOf`. The documentation for `setPrototypeOf` says to use
// `Object.create` or `Reflect.construct` instead for performance reasons
// but neither of those work here.
target = function () {};
target = function () { };
Object.setPrototypeOf(target, cls.prototype);
// Remove undesirable properties added by Function constructor. Note: we
// can't remove "arguments" or "caller" because they are not configurable
Expand Down Expand Up @@ -408,7 +408,7 @@ Module.getPyProxyClass = function (flags: number) {
);
const super_proto = flags & IS_CALLABLE ? PyProxyFunctionProto : PyProxyProto;
const sub_proto = Object.create(super_proto, descriptors);
function NewPyProxyClass() {}
function NewPyProxyClass() { }
NewPyProxyClass.prototype = sub_proto;
pyproxyClassMap.set(flags, NewPyProxyClass);
return NewPyProxyClass;
Expand Down Expand Up @@ -819,7 +819,7 @@ const PyProxyFunctionProto = Object.create(
Function.prototype,
Object.getOwnPropertyDescriptors(PyProxyProto),
);
function PyProxyFunction() {}
function PyProxyFunction() { }
PyProxyFunction.prototype = PyProxyFunctionProto;

/**
Expand All @@ -833,7 +833,7 @@ export class PyProxyWithLength extends PyProxy {
}
}

export interface PyProxyWithLength extends PyLengthMethods {}
export interface PyProxyWithLength extends PyLengthMethods { }

// Controlled by HAS_LENGTH, appears for any object with __len__ or sq_length
// or mp_length methods
Expand Down Expand Up @@ -869,7 +869,7 @@ export class PyProxyWithGet extends PyProxy {
}
}

export interface PyProxyWithGet extends PyGetItemMethods {}
export interface PyProxyWithGet extends PyGetItemMethods { }

class PyAsJsonAdaptorMethods {
asJsJson() {
Expand Down Expand Up @@ -954,7 +954,7 @@ export class PyProxyWithSet extends PyProxy {
}
}

export interface PyProxyWithSet extends PySetItemMethods {}
export interface PyProxyWithSet extends PySetItemMethods { }
// Controlled by HAS_SET, appears for any class with __setitem__, __delitem__,
// mp_ass_subscript, or sq_ass_item.
export class PySetItemMethods {
Expand Down Expand Up @@ -1010,7 +1010,7 @@ export class PyProxyWithHas extends PyProxy {
}
}

export interface PyProxyWithHas extends PyContainsMethods {}
export interface PyProxyWithHas extends PyContainsMethods { }

// Controlled by HAS_CONTAINS flag, appears for any class with __contains__ or
// sq_contains
Expand Down Expand Up @@ -1089,7 +1089,7 @@ function* iter_helper(
"This borrowed proxy was automatically destroyed when an iterator was exhausted.",
),
);
} catch (e) {}
} catch (e) { }
if (_PyErr_Occurred()) {
_pythonexc2js();
}
Expand All @@ -1108,7 +1108,7 @@ export class PyIterable extends PyProxy {
}
}

export interface PyIterable extends PyIterableMethods {}
export interface PyIterable extends PyIterableMethods { }

// Controlled by IS_ITERABLE, appears for any object with __iter__ or tp_iter,
// unless they are iterators. See: https://docs.python.org/3/c-api/iter.html
Expand Down Expand Up @@ -1216,7 +1216,7 @@ export class PyAsyncIterable extends PyProxy {
}
}

export interface PyAsyncIterable extends PyAsyncIterableMethods {}
export interface PyAsyncIterable extends PyAsyncIterableMethods { }

export class PyAsyncIterableMethods {
/**
Expand Down Expand Up @@ -1257,7 +1257,7 @@ export class PyIterator extends PyProxy {
}
}

export interface PyIterator extends PyIteratorMethods {}
export interface PyIterator extends PyIteratorMethods { }

// Controlled by IS_ITERATOR, appears for any object with a __next__ or
// tp_iternext method.
Expand Down Expand Up @@ -1310,7 +1310,7 @@ export class PyGenerator extends PyProxy {
}
}

export interface PyGenerator extends PyGeneratorMethods {}
export interface PyGenerator extends PyGeneratorMethods { }

export class PyGeneratorMethods {
/**
Expand Down Expand Up @@ -1386,7 +1386,7 @@ export class PyAsyncIterator extends PyProxy {
}
}

export interface PyAsyncIterator extends PyAsyncIteratorMethods {}
export interface PyAsyncIterator extends PyAsyncIteratorMethods { }

export class PyAsyncIteratorMethods {
/** @private */
Expand Down Expand Up @@ -1450,7 +1450,7 @@ export class PyAsyncGenerator extends PyProxy {
}
}

export interface PyAsyncGenerator extends PyAsyncGeneratorMethods {}
export interface PyAsyncGenerator extends PyAsyncGeneratorMethods { }

export class PyAsyncGeneratorMethods {
/**
Expand Down Expand Up @@ -1553,7 +1553,7 @@ export class PySequence extends PyProxy {
}
}

export interface PySequence extends PySequenceMethods {}
export interface PySequence extends PySequenceMethods { }

// JS default comparison is to convert to strings and compare lexicographically
function defaultCompareFunc(a: any, b: any): number {
Expand Down Expand Up @@ -1860,7 +1860,7 @@ export class PyMutableSequence extends PyProxy {
}
}

export interface PyMutableSequence extends PyMutableSequenceMethods {}
export interface PyMutableSequence extends PyMutableSequenceMethods { }

export class PyMutableSequenceMethods {
/**
Expand Down Expand Up @@ -2433,7 +2433,7 @@ export class PyAwaitable extends PyProxy {
}
}

export interface PyAwaitable extends Promise<any> {}
export interface PyAwaitable extends Promise<any> { }

/**
* The Promise / JavaScript awaitable API.
Expand Down Expand Up @@ -2847,7 +2847,7 @@ export class PyBuffer extends PyProxy {
}
}

export interface PyBuffer extends PyBufferMethods {}
export interface PyBuffer extends PyBufferMethods { }

export class PyBufferMethods {
/**
Expand Down Expand Up @@ -2922,11 +2922,11 @@ export class PyBufferMethods {
if (bigEndian && alignment > 1) {
throw new Error(
"Javascript has no native support for big endian buffers. " +
"In this case, you can pass an explicit type argument. " +
"For instance, `getBuffer('dataview')` will return a `DataView`" +
"which has native support for reading big endian data. " +
"Alternatively, toJs will automatically convert the buffer " +
"to little endian.",
"In this case, you can pass an explicit type argument. " +
"For instance, `getBuffer('dataview')` will return a `DataView`" +
"which has native support for reading big endian data. " +
"Alternatively, toJs will automatically convert the buffer " +
"to little endian.",
);
}
let numBytes = largest_ptr - smallest_ptr;
Expand Down Expand Up @@ -3001,10 +3001,10 @@ export class PyDict extends PyProxy {

export interface PyDict
extends PyProxyWithGet,
PyProxyWithSet,
PyProxyWithHas,
PyProxyWithLength,
PyIterable {}
PyProxyWithSet,
PyProxyWithHas,
PyProxyWithLength,
PyIterable { }

/**
* A class to allow access to Python data buffers from JavaScript. These are
Expand Down
10 changes: 5 additions & 5 deletions src/js/api.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { ffi } from "./ffi";
import { CanvasInterface, canvas } from "./canvas";
import { type CanvasInterface, canvas } from "./canvas";

import { PackageData, loadPackage, loadedPackages } from "./load-package";
import { type PyProxy, type PyDict } from "generated/pyproxy";
import { type PackageData, loadPackage, loadedPackages } from "./load-package";
import { type PyProxy, type PyDict } from "./generated/pyproxy";
import { loadBinaryFile } from "./compat";
import { version } from "./version";
import { setStdin, setStdout, setStderr } from "./streams";
import { scheduleCallback } from "./scheduler";
import { TypedArray } from "./types";
import type { TypedArray } from "./types";
import { detectEnvironment } from "./environments";
import "./literal-map.js";
import {
makeGlobalsProxy,
SnapshotConfig,
type SnapshotConfig,
syncUpSnapshotLoad1,
syncUpSnapshotLoad2,
} from "./snapshot";
Expand Down
2 changes: 1 addition & 1 deletion src/js/compat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
IN_BROWSER_MAIN_THREAD,
IN_BROWSER_WEB_WORKER,
} from "./environments";
import { Lockfile } from "./types";
import type { Lockfile } from "./types";

declare var globalThis: {
importScripts: (url: string) => void;
Expand Down
9 changes: 4 additions & 5 deletions src/js/dynload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ declare var DEBUG: boolean;

import { createLock } from "./lock";
import { memoize } from "./pyodide-util";
import { InternalPackageData } from "./load-package";
import { LoadDynlibFS, ReadFileType } from "./types";
import type { InternalPackageData } from "./load-package";
import type { LoadDynlibFS, ReadFileType } from "./types";

// File System-like type which can be passed to
// Module.loadDynamicLibrary or Module.loadWebAssemblyModule
Expand Down Expand Up @@ -153,9 +153,8 @@ export async function loadDynlibsFromPackage(
) {
// assume that shared libraries of a package are located in <package-name>.libs directory,
// following the convention of auditwheel.
const auditWheelLibDir = `${API.sitepackages}/${
pkg.file_name.split("-")[0]
}.libs`;
const auditWheelLibDir = `${API.sitepackages}/${pkg.file_name.split("-")[0]
}.libs`;

// This prevents from reading large libraries multiple times.
const readFileMemoized: ReadFileType = memoize(Module.FS.readFile);
Expand Down
4 changes: 2 additions & 2 deletions src/js/emscripten-settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @private */

import { ConfigType } from "./pyodide";
import type { ConfigType } from "./pyodide";
import { loadBinaryFile, getBinaryResponse } from "./compat";
import { API, PreRunFunc } from "./types";
import type { API, PreRunFunc } from "./types";

/**
* @private
Expand Down
8 changes: 4 additions & 4 deletions src/js/ffi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export type {
PyBufferView,
PySequence,
PyMutableSequence,
} from "generated/pyproxy";
export type { PythonError } from "generated/error_handling";
} from "./generated/pyproxy";
export type { PythonError } from "./generated/error_handling";
// These need to be imported for their side effects at startup
import "generated/js2python";
import "generated/python2js_buffer";
Expand All @@ -44,9 +44,9 @@ import {
PyBufferView,
PySequence,
PyMutableSequence,
} from "generated/pyproxy";
} from "./generated/pyproxy";

import { PythonError } from "../core/error_handling";
import { PythonError } from "./generated/error_handling";

/**
* See :ref:`js-api-pyodide-ffi`
Expand Down
4 changes: 2 additions & 2 deletions src/js/load-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
} from "./compat.js";
import { createLock } from "./lock";
import { loadDynlibsFromPackage } from "./dynload";
import { PyProxy } from "generated/pyproxy";
import { PyProxy } from "./generated/pyproxy";
import {
canonicalizePackageName,
uriToPackageData,
base16ToBase64,
} from "./packaging-utils";
import { Lockfile } from "./types";
import type { Lockfile } from "./types";

/**
* Initialize the packages index. This is called as early as possible in
Expand Down
16 changes: 10 additions & 6 deletions src/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"access": "public"
},
"version": "0.26.2",
"type": "module",
"description": "The Pyodide JavaScript package",
"keywords": [
"python",
Expand All @@ -22,18 +23,21 @@
".": {
"import": "./dist/pyodide.js",
"types": "./pyodide.ts"
},
"./version": {
"import": "./version.ts",
"types": "./version.ts"
}
},
"files": [
"package.json",
"dist",
"pyodide.ts",
"api.ts",
"types.ts",
"emscripten-settings.ts",
"snapshot.ts"
"generated",
"vendor",
"*.ts"
],
"types": "./pyodide.ts",
"engines": {
"node": ">=18.0.0"
}
}
}
2 changes: 1 addition & 1 deletion src/js/pyodide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { PyodideInterface } from "./api.js";
import type { TypedArray, Module } from "./types";
import type { EmscriptenSettings } from "./emscripten-settings";
import type { PackageData } from "./load-package";
import { SnapshotConfig } from "./snapshot";
import type { SnapshotConfig } from "./snapshot";
export type { PyodideInterface, TypedArray };

export { version, type PackageData };
Expand Down
Loading

0 comments on commit 85edbac

Please sign in to comment.