Skip to content

Commit 2b09d4f

Browse files
Copilotstephentoub
andauthored
Fix Python codegen: strip quicktype duplicate imports and trailing whitespace
Agent-Logs-Url: https://github.com/github/copilot-sdk/sessions/a6ce684b-599e-45bd-956a-c351c5699f53 Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 9a214e6 commit 2b09d4f

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

python/copilot/generated/rpc.py

Lines changed: 10 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/codegen/python.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,14 @@ async function generateRpc(schemaPath?: string): Promise<void> {
14541454
typesCode = modernizePython(typesCode);
14551455
typesCode = collapsePlaceholderPythonDataclasses(typesCode);
14561456

1457+
// Strip quicktype's import block and preamble — we provide our own unified header.
1458+
// The preamble ends just before the first helper function (e.g. "def from_str")
1459+
// or class definition.
1460+
typesCode = typesCode.replace(/^[\s\S]*?(?=^(?:def |@dataclass|class )\w)/m, "");
1461+
1462+
// Strip trailing whitespace from blank lines (e.g. inside multi-line docstrings)
1463+
typesCode = typesCode.replace(/^\s+$/gm, "");
1464+
14571465
// Annotate experimental data types
14581466
const experimentalTypeNames = new Set<string>();
14591467
for (const method of allMethods) {
@@ -1494,7 +1502,15 @@ if TYPE_CHECKING:
14941502
14951503
from collections.abc import Callable
14961504
from dataclasses import dataclass
1497-
from typing import Protocol
1505+
from datetime import datetime
1506+
from enum import Enum
1507+
from typing import Any, Protocol, TypeVar, cast
1508+
from uuid import UUID
1509+
1510+
import dateutil.parser
1511+
1512+
T = TypeVar("T")
1513+
EnumT = TypeVar("EnumT", bound=Enum)
14981514
14991515
`);
15001516
lines.push(typesCode);

0 commit comments

Comments
 (0)