A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
chore(frontend): Remove simple cases of `as any` (#5440)
Trevor Manz8acf283f30c2
diff --git a/frontend/src/components/data-table/column-summary.tsx b/frontend/src/components/data-table/column-summary.tsxindex 0aeb0a15ec..bfaa85feec 100644--- a/frontend/src/components/data-table/column-summary.tsx+++ b/frontend/src/components/data-table/column-summary.tsx@@ -47,8 +47,8 @@ export const TableColumnSummary = <TData, TValue>({spec={spec}width={70}height={30}- // eslint-disable-next-line @typescript-eslint/no-explicit-any- loader={batchedLoader as any}+ // @ts-expect-error - Our `loader.load` method is broader than VegaLite's typings but is functionally supported.+ loader={batchedLoader}style={{ minWidth: "unset", maxHeight: "40px" }}actions={false}theme={theme === "dark" ? "dark" : "vox"}diff --git a/frontend/src/components/data-table/columns.tsx b/frontend/src/components/data-table/columns.tsxindex 6adbfd318e..f0d2a0aeaf 100644--- a/frontend/src/components/data-table/columns.tsx+++ b/frontend/src/components/data-table/columns.tsx@@ -68,12 +68,12 @@ export function inferFieldTypes<T>(items: T[]): FieldTypesWithExternalType {// This can be slow for large datasets,// so only sample 10 evenly distributed rowsuniformSample(items, 10).forEach((item) => {- if (typeof item !== "object") {+ if (typeof item !== "object" || item === null) {return;}// We will be a bit defensive and assume values are not homogeneous.// If any is a mimetype, then we will treat it as a mimetype (i.e. not sortable)- Object.entries(item as object).forEach(([key, value], idx) => {+ Object.entries(item).forEach(([key, value], idx) => {const currentValue = fieldTypes[key];if (!currentValue) {// Set for the first time@@ -152,8 +152,7 @@ export function generateColumns<T>({// may have periods in them ...// https://github.com/TanStack/table/issues/1671accessorFn: (row) => {- // eslint-disable-next-line @typescript-eslint/no-explicit-any- return (row as any)[key];+ return row[key as keyof T];},header: ({ column }) => {diff --git a/frontend/src/core/codemirror/lsp/notebook-lsp.ts b/frontend/src/core/codemirror/lsp/notebook-lsp.tsindex a9d279f39c..5681ef6768 100644--- a/frontend/src/core/codemirror/lsp/notebook-lsp.ts+++ b/frontend/src/core/codemirror/lsp/notebook-lsp.ts@@ -1,6 +1,5 @@/* Copyright 2024 Marimo. All rights reserved. */-import type { EditorView } from "@codemirror/view";import type * as LSP from "vscode-languageserver-protocol";import type { CellId } from "@/core/cells/ids";import { invariant } from "@/utils/invariant";@@ -11,7 +10,8 @@ import { createNotebookLens } from "./lens";import {CellDocumentUri,type ILanguageServerClient,- isNotifyingClient,+ isClientWithNotify,+ isClientWithPlugins,} from "./types";import { getLSPDocument } from "./utils";@@ -46,7 +46,7 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {// Handle configuration after initializationthis.initializePromise.then(() => {invariant(- isNotifyingClient(this.client),+ isClientWithNotify(this.client),"notify is not a method on the client",);this.client.notify("workspace/didChangeConfiguration", {@@ -205,9 +205,13 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {const newEdits = lens.getEditsForNewText(edit.newText);const editsToNewCode = new Map(newEdits.map((e) => [e.cellId, e.text]));+ invariant(+ isClientWithPlugins(this.client),+ "Expected client with plugins.",+ );+// Update the code in the plugins manually- // eslint-disable-next-line @typescript-eslint/no-explicit-any- for (const plugin of (this.client as any).plugins) {+ for (const plugin of this.client.plugins) {const documentUri: string = plugin.documentUri;if (!CellDocumentUri.is(documentUri)) {Logger.warn("Invalid cell document URI", documentUri);@@ -221,16 +225,19 @@ export class NotebookLanguageServerClient implements ILanguageServerClient {continue;}- const view: EditorView = plugin.view;- if (!view) {+ if (!plugin.view) {Logger.warn("No view for plugin", plugin);continue;}// Only update if it has changed- if (view.state.doc.toString() !== newCode) {- view.dispatch({- changes: { from: 0, to: view.state.doc.length, insert: newCode },+ if (plugin.view.state.doc.toString() !== newCode) {+ plugin.view.dispatch({+ changes: {+ from: 0,+ to: plugin.view.state.doc.length,+ insert: newCode,+ },});}}diff --git a/frontend/src/core/codemirror/lsp/types.ts b/frontend/src/core/codemirror/lsp/types.tsindex f4c46fc8f7..ad64ad76e4 100644--- a/frontend/src/core/codemirror/lsp/types.ts+++ b/frontend/src/core/codemirror/lsp/types.ts@@ -1,5 +1,6 @@/* Copyright 2024 Marimo. All rights reserved. */+import type { EditorView } from "@codemirror/view";import type { LanguageServerClient } from "@marimo-team/codemirror-languageserver";import type { DocumentUri } from "vscode-languageserver-protocol";import type { CellId } from "@/core/cells/ids";@@ -30,7 +31,7 @@ export const CellDocumentUri = {* Notify is a @protected method on `LanguageServerClient`,* hiding public use with TypeScript.*/-export function isNotifyingClient(+export function isClientWithNotify(client: ILanguageServerClient,): client is ILanguageServerClient & {notify: (@@ -40,3 +41,15 @@ export function isNotifyingClient(} {return "notify" in client;}++/**+ * Plugins are a @private on `LanguageServerClient`,+ * hiding public use with TypeScript.+ */+export function isClientWithPlugins(+ client: ILanguageServerClient,+): client is ILanguageServerClient & {+ plugins: Array<{ documentUri: string; view?: EditorView }>;+} {+ return "plugins" in client;+}