diff --git a/.chronus/changes/type-import-emitter-python-2026-7-31.md b/.chronus/changes/type-import-emitter-python-2026-7-31.md new file mode 100644 index 00000000000..c14a674ed5d --- /dev/null +++ b/.chronus/changes/type-import-emitter-python-2026-7-31.md @@ -0,0 +1,7 @@ +--- +changeKind: internal +packages: + - "@typespec/http-client-python" +--- + +Enable `verbatimModuleSyntax` in the emitter's TypeScript config and convert type-only imports/exports to `import type`/`export type`. diff --git a/packages/http-client-python/emitter/src/code-model.ts b/packages/http-client-python/emitter/src/code-model.ts index 28f8d4d8489..ec82bac332d 100644 --- a/packages/http-client-python/emitter/src/code-model.ts +++ b/packages/http-client-python/emitter/src/code-model.ts @@ -1,4 +1,4 @@ -import { +import type { SdkBasicServiceMethod, SdkClientType, SdkCredentialParameter, @@ -12,6 +12,8 @@ import { SdkServiceMethod, SdkServiceOperation, SdkUnionType, +} from "@azure-tools/typespec-client-generator-core"; +import { UsageFlags, getCrossLanguagePackageId, isAzureCoreModel, @@ -24,7 +26,7 @@ import { emitLroPagingHttpMethod, emitPagingHttpMethod, } from "./http.js"; -import { PythonSdkContext } from "./lib.js"; +import type { PythonSdkContext } from "./lib.js"; import { KnownTypes, emitEndpointType, getType } from "./types.js"; import { emitParamBase, getClientNamespace, getImplementation, getRootNamespace } from "./utils.js"; diff --git a/packages/http-client-python/emitter/src/emitter.ts b/packages/http-client-python/emitter/src/emitter.ts index 9e0489ee2e3..e06a6105c32 100644 --- a/packages/http-client-python/emitter/src/emitter.ts +++ b/packages/http-client-python/emitter/src/emitter.ts @@ -1,5 +1,6 @@ import { createSdkContext } from "@azure-tools/typespec-client-generator-core"; -import { EmitContext, emitFile, joinPaths, NoTarget } from "@typespec/compiler"; +import type { EmitContext } from "@typespec/compiler"; +import { emitFile, joinPaths, NoTarget } from "@typespec/compiler"; import pkgJson from "../../package.json" with { type: "json" }; import { emitCodeModel } from "./code-model.js"; import { @@ -9,9 +10,11 @@ import { PYODIDE_VERSION, } from "./constants.js"; import { dumpCodeModelToYaml } from "./external-process.js"; -import { PythonEmitterOptions, PythonSdkContext, reportDiagnostic } from "./lib.js"; +import type { PythonEmitterOptions, PythonSdkContext } from "./lib.js"; +import { reportDiagnostic } from "./lib.js"; import { runNodeEmit } from "./node-runner.js"; -import { loadPyodide, PyodideInterface } from "./pyodide-loader.js"; +import type { PyodideInterface } from "./pyodide-loader.js"; +import { loadPyodide } from "./pyodide-loader.js"; import { getRootNamespace, md2Rst } from "./utils.js"; function getBrowserPygenWheelUrl(): string { diff --git a/packages/http-client-python/emitter/src/external-process.ts b/packages/http-client-python/emitter/src/external-process.ts index 8c3b0486286..74f0b3b2cbf 100644 --- a/packages/http-client-python/emitter/src/external-process.ts +++ b/packages/http-client-python/emitter/src/external-process.ts @@ -1,5 +1,6 @@ import { joinPaths } from "@typespec/compiler"; -import { ChildProcess, spawn, SpawnOptions } from "child_process"; +import type { ChildProcess, SpawnOptions } from "child_process"; +import { spawn } from "child_process"; import { randomUUID } from "crypto"; import { mkdir, writeFile } from "fs/promises"; import jsyaml from "js-yaml"; diff --git a/packages/http-client-python/emitter/src/http.ts b/packages/http-client-python/emitter/src/http.ts index 5e9744706c8..31d970d4b65 100644 --- a/packages/http-client-python/emitter/src/http.ts +++ b/packages/http-client-python/emitter/src/http.ts @@ -1,7 +1,6 @@ import { getNamespaceFullName, NoTarget } from "@typespec/compiler"; -import { - getHttpOperationParameter, +import type { SdkBasicServiceMethod, SdkBodyParameter, SdkClientType, @@ -20,10 +19,11 @@ import { SdkServiceMethod, SdkServiceResponseHeader, SdkType, - UsageFlags, } from "@azure-tools/typespec-client-generator-core"; -import { HttpStatusCodeRange } from "@typespec/http"; -import { PythonSdkContext, reportDiagnostic } from "./lib.js"; +import { getHttpOperationParameter, UsageFlags } from "@azure-tools/typespec-client-generator-core"; +import type { HttpStatusCodeRange } from "@typespec/http"; +import type { PythonSdkContext } from "./lib.js"; +import { reportDiagnostic } from "./lib.js"; import { getType, KnownTypes } from "./types.js"; import { emitParamBase, diff --git a/packages/http-client-python/emitter/src/index.ts b/packages/http-client-python/emitter/src/index.ts index ddfe2de55d4..b6848e3d4db 100644 --- a/packages/http-client-python/emitter/src/index.ts +++ b/packages/http-client-python/emitter/src/index.ts @@ -1,2 +1,3 @@ export * from "./emitter.js"; -export { $lib, PythonEmitterOptions, PythonEmitterOptionsSchema } from "./lib.js"; +export { $lib, PythonEmitterOptionsSchema } from "./lib.js"; +export type { PythonEmitterOptions } from "./lib.js"; diff --git a/packages/http-client-python/emitter/src/lib.ts b/packages/http-client-python/emitter/src/lib.ts index 70d5d0d081f..6c00620466a 100644 --- a/packages/http-client-python/emitter/src/lib.ts +++ b/packages/http-client-python/emitter/src/lib.ts @@ -1,9 +1,7 @@ -import { - SdkContext, - SdkType, - UnbrandedSdkEmitterOptions, -} from "@azure-tools/typespec-client-generator-core"; -import { createTypeSpecLibrary, JSONSchemaType, paramMessage } from "@typespec/compiler"; +import type { SdkContext, SdkType } from "@azure-tools/typespec-client-generator-core"; +import { UnbrandedSdkEmitterOptions } from "@azure-tools/typespec-client-generator-core"; +import type { JSONSchemaType } from "@typespec/compiler"; +import { createTypeSpecLibrary, paramMessage } from "@typespec/compiler"; export interface PythonEmitterOptions { "api-version"?: string; diff --git a/packages/http-client-python/emitter/src/node-runner.browser.ts b/packages/http-client-python/emitter/src/node-runner.browser.ts index bc548efdf8a..4003318376f 100644 --- a/packages/http-client-python/emitter/src/node-runner.browser.ts +++ b/packages/http-client-python/emitter/src/node-runner.browser.ts @@ -6,7 +6,8 @@ import type { EmitContext } from "@typespec/compiler"; import { NoTarget } from "@typespec/compiler"; import type { PyodideInterface } from "pyodide"; -import { PythonEmitterOptions, reportDiagnostic } from "./lib.js"; +import type { PythonEmitterOptions } from "./lib.js"; +import { reportDiagnostic } from "./lib.js"; export interface RunNodeEmitArgs { context: EmitContext; diff --git a/packages/http-client-python/emitter/src/node-runner.ts b/packages/http-client-python/emitter/src/node-runner.ts index 1d75b7c4c59..399ebcfd593 100644 --- a/packages/http-client-python/emitter/src/node-runner.ts +++ b/packages/http-client-python/emitter/src/node-runner.ts @@ -5,16 +5,19 @@ // `node-runner.browser.ts` stub is swapped in via the `"browser"` field in // `package.json` when bundling with `platform: "browser"`. -import { EmitContext, NoTarget } from "@typespec/compiler"; +import type { EmitContext } from "@typespec/compiler"; +import { NoTarget } from "@typespec/compiler"; import { execSync } from "child_process"; import fs from "fs"; import os from "os"; import path, { dirname } from "path"; -import { loadPyodide, PyodideInterface } from "pyodide"; +import type { PyodideInterface } from "pyodide"; +import { loadPyodide } from "pyodide"; import { fileURLToPath } from "url"; import { blackExcludeDirs, PYGEN_WHEEL_FILENAME } from "./constants.js"; import { saveCodeModelAsYaml } from "./external-process.js"; -import { PythonEmitterOptions, reportDiagnostic } from "./lib.js"; +import type { PythonEmitterOptions } from "./lib.js"; +import { reportDiagnostic } from "./lib.js"; import { runPython3 } from "./run-python3.js"; import { quoteShellArg } from "./utils.js"; diff --git a/packages/http-client-python/emitter/src/system-requirements.ts b/packages/http-client-python/emitter/src/system-requirements.ts index 32521654c1b..b50dc75c667 100644 --- a/packages/http-client-python/emitter/src/system-requirements.ts +++ b/packages/http-client-python/emitter/src/system-requirements.ts @@ -1,4 +1,5 @@ -import { ChildProcess, spawn, SpawnOptions } from "child_process"; +import type { ChildProcess, SpawnOptions } from "child_process"; +import { spawn } from "child_process"; import { coerce, satisfies } from "semver"; /* diff --git a/packages/http-client-python/emitter/src/types.ts b/packages/http-client-python/emitter/src/types.ts index 97619c96b7b..617f26f62cf 100644 --- a/packages/http-client-python/emitter/src/types.ts +++ b/packages/http-client-python/emitter/src/types.ts @@ -1,5 +1,4 @@ -import { - isHttpMetadata, +import type { SdkArrayType, SdkBuiltInType, SdkConstantType, @@ -14,12 +13,14 @@ import { SdkModelType, SdkType, SdkUnionType, - UsageFlags, } from "@azure-tools/typespec-client-generator-core"; -import { getEncode, Type } from "@typespec/compiler"; -import { HttpAuth, Visibility } from "@typespec/http"; +import { isHttpMetadata, UsageFlags } from "@azure-tools/typespec-client-generator-core"; +import type { Type } from "@typespec/compiler"; +import { getEncode } from "@typespec/compiler"; +import type { HttpAuth } from "@typespec/http"; +import { Visibility } from "@typespec/http"; import { dump } from "js-yaml"; -import { PythonSdkContext } from "./lib.js"; +import type { PythonSdkContext } from "./lib.js"; import { camelToSnakeCase, emitParamBase, diff --git a/packages/http-client-python/emitter/src/utils.ts b/packages/http-client-python/emitter/src/utils.ts index 2f4c22ee57e..3258d6982ce 100644 --- a/packages/http-client-python/emitter/src/utils.ts +++ b/packages/http-client-python/emitter/src/utils.ts @@ -1,5 +1,4 @@ -import { - InitializedByFlags, +import type { SdkCredentialParameter, SdkEndpointParameter, SdkHeaderParameter, @@ -13,9 +12,11 @@ import { SdkServiceResponseHeader, SdkType, } from "@azure-tools/typespec-client-generator-core"; +import { InitializedByFlags } from "@azure-tools/typespec-client-generator-core"; import { getNamespaceFullName } from "@typespec/compiler"; -import { marked, Token } from "marked"; -import { PythonSdkContext } from "./lib.js"; +import type { Token } from "marked"; +import { marked } from "marked"; +import type { PythonSdkContext } from "./lib.js"; import { getSimpleTypeResult, getType } from "./types.js"; function IsFullyUpperCase(identifier: string, maxUppercasePreserve: number) { diff --git a/packages/http-client-python/emitter/tsconfig.json b/packages/http-client-python/emitter/tsconfig.json index 99589e3efe4..345bb3f8ee1 100644 --- a/packages/http-client-python/emitter/tsconfig.json +++ b/packages/http-client-python/emitter/tsconfig.json @@ -2,7 +2,8 @@ "extends": "../../../tsconfig.base.json", "compilerOptions": { "noEmit": true, - "resolveJsonModule": true + "resolveJsonModule": true, + "verbatimModuleSyntax": true }, "include": ["src/**/*"] }