Skip to content

Commit

Permalink
use future annotations instead of explicit forward declare for python
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcphers committed Jan 3, 2024
1 parent e3c8ca3 commit 4bb8ce5
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions positron/comms/generate-comms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<string>,
o: Record<string, any>) {
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<string>, values: Array<string>) {
yield '@enum.unique\n';
Expand Down

0 comments on commit 4bb8ce5

Please sign in to comment.