From 4bb8ce5acf46f3e3772a6df6458090a03f600cb9 Mon Sep 17 00:00:00 2001 From: Jonathan McPherson Date: Wed, 3 Jan 2024 13:38:36 -0800 Subject: [PATCH] use future annotations instead of explicit forward declare for python --- positron/comms/generate-comms.ts | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/positron/comms/generate-comms.ts b/positron/comms/generate-comms.ts index 08ee616c184..e688f533176 100644 --- a/positron/comms/generate-comms.ts +++ b/positron/comms/generate-comms.ts @@ -572,6 +572,9 @@ function* createPythonComm(name: string, # AUTO-GENERATED from ${name}.json; do not edit. # +# For forward declarations +from __future__ import annotations + import enum from dataclasses import dataclass, field from typing import Dict, List, Union, Optional @@ -584,20 +587,6 @@ JsonData = Union[Dict[str, "JsonData"], List["JsonData"], str, int, float, bool, continue; } - // Forward declare all the object types. This is necessary because the - // OpenRPC contracts are not in dependency order (or may have cyclical - // dependencies), and Python requires that all types be defined before - // they are used. - yield '# Forward declarations\n'; - yield* objectVisitor([], source, function* ( - context: Array, - o: Record) { - let name = o.name ? o.name : context[0] === 'items' ? context[1] : context[0]; - name = snakeCaseToSentenceCase(name); - yield `class ${name}:\n`; - yield ` pass\n`; - }); - // Create enums for all enum types yield* enumVisitor([], source, function* (context: Array, values: Array) { yield '@enum.unique\n';