Skip to content

Commit

Permalink
NFC Python: Tidy up some typescript types (#2985)
Browse files Browse the repository at this point in the history
I removed some ts-ignores
  • Loading branch information
hoodmane authored Oct 24, 2024
1 parent c0d90a4 commit 08d3a63
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/pyodide/internal/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ function recordDsoHandles(Module: Module): DylinkInfo {
// whose importer is not FrozenImporter or BuiltinImporter.
//
const SNAPSHOT_IMPORTS: string[] =
// @ts-ignore getSnapshotImports is a static method.
ArtifactBundler.constructor.getSnapshotImports();

/**
Expand All @@ -206,7 +205,7 @@ const SNAPSHOT_IMPORTS: string[] =
*
* This function returns a list of modules that have been imported.
*/
function memorySnapshotDoImports(Module: Module): Array<string> {
function memorySnapshotDoImports(Module: Module): string[] {
const toImport = SNAPSHOT_IMPORTS.join(',');
const toDelete = Array.from(
new Set(SNAPSHOT_IMPORTS.map((x) => x.split('.', 1)[0]))
Expand All @@ -230,13 +229,12 @@ function memorySnapshotDoImports(Module: Module): Array<string> {
// The `importedModules` list will contain all modules that have been imported, including local
// modules, the usual `js` and other stdlib modules. We want to filter out local imports, so we
// grab them and put them into a set for fast filtering.
const importedModules: Array<string> =
// @ts-ignore filterPythonScriptImportsJs is a static method.
const importedModules: string[] =
ArtifactBundler.constructor.filterPythonScriptImportsJs(
MetadataReader.getNames(),
ArtifactBundler.constructor
// @ts-ignore parsePythonScriptImports is a static method.
.parsePythonScriptImports(MetadataReader.getWorkerFiles('py'))
ArtifactBundler.constructor.parsePythonScriptImports(
MetadataReader.getWorkerFiles('py')
)
);

const deduplicatedModules = [...new Set(importedModules)];
Expand Down Expand Up @@ -285,7 +283,7 @@ function makeLinearMemorySnapshot(

function setUploadFunction(
snapshot: Uint8Array,
importedModulesList: Array<string>
importedModulesList: string[]
): void {
if (snapshot.constructor.name !== 'Uint8Array') {
throw new TypeError('Expected TO_UPLOAD to be a Uint8Array');
Expand Down
2 changes: 1 addition & 1 deletion src/pyodide/types/FS.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ interface FS {
mode: number
): FSNode<Info>;
isFile: (mode: number) => boolean;
readdir: (path: string) => Array<string>;
readdir: (path: string) => string[];
genericErrors: Error[];
}

Expand Down
11 changes: 10 additions & 1 deletion src/pyodide/types/artifacts.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
declare namespace ArtifactBundler {
const constructor: {
getSnapshotImports(): string[];
filterPythonScriptImportsJs(
fileNames: string[],
imports: string[]
): string[];
parsePythonScriptImports(fileNames: string[]): string[];
};

type MemorySnapshotResult = {
snapshot: Uint8Array;
importedModulesList: Array<string>;
importedModulesList: string[];
};

const hasMemorySnapshot: () => boolean;
Expand Down

0 comments on commit 08d3a63

Please sign in to comment.