Skip to content

Commit f3486b2

Browse files
authored
Python: fix invalid type annotations and undefined variables (#292)
* Python: fix invalid type annotations and undefined variables * restore identation
1 parent 36756e3 commit f3486b2

File tree

2 files changed

+33
-34
lines changed

2 files changed

+33
-34
lines changed

design/mvp/CanonicalABI.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ functions of components in the Component Model and the values and functions
55
of modules in Core WebAssembly.
66

77
* [Supporting definitions](#supporting-definitions)
8-
* [Despecialization](#Despecialization)
8+
* [Despecialization](#despecialization)
99
* [Alignment](#alignment)
1010
* [Size](#size)
1111
* [Runtime State](#runtime-state)
@@ -15,7 +15,6 @@ of modules in Core WebAssembly.
1515
* [Flat Lifting](#flat-lifting)
1616
* [Flat Lowering](#flat-lowering)
1717
* [Lifting and Lowering Values](#lifting-and-lowering-values)
18-
* [Lifting and Lowering Functions](#lifting-and-lowering-functions)
1918
* [Canonical definitions](#canonical-definitions)
2019
* [`canon lift`](#canon-lift)
2120
* [`canon lower`](#canon-lower)
@@ -220,7 +219,7 @@ definitions via the `cx` parameter of type `CallContext`:
220219
class CallContext:
221220
opts: CanonicalOptions
222221
inst: ComponentInstance
223-
lenders: [HandleElem]
222+
lenders: list[HandleElem]
224223
borrow_count: int
225224

226225
def __init__(self, opts, inst):
@@ -346,8 +345,8 @@ of handles that all share the same `ResourceType`. Defining `HandleTable` in
346345
chunks, we start with the fields and `get` method:
347346
```python
348347
class HandleTable:
349-
array: [Optional[HandleElem]]
350-
free: [int]
348+
array: list[Optional[HandleElem]]
349+
free: list[int]
351350

352351
def __init__(self):
353352
self.array = [None]
@@ -450,8 +449,8 @@ def load(cx, ptr, t):
450449
case Record(fields) : return load_record(cx, ptr, fields)
451450
case Variant(cases) : return load_variant(cx, ptr, cases)
452451
case Flags(labels) : return load_flags(cx, ptr, labels)
453-
case Own() : return lift_own(cx, load_int(opts, ptr, 4), t)
454-
case Borrow() : return lift_borrow(cx, load_int(opts, ptr, 4), t)
452+
case Own() : return lift_own(cx, load_int(cx.opts, ptr, 4), t)
453+
case Borrow() : return lift_borrow(cx, load_int(cx.opts, ptr, 4), t)
455454
```
456455

457456
Integers are loaded directly from memory, with their high-order bit interpreted
@@ -702,8 +701,8 @@ def store(cx, v, t, ptr):
702701
case Record(fields) : store_record(cx, v, ptr, fields)
703702
case Variant(cases) : store_variant(cx, v, ptr, cases)
704703
case Flags(labels) : store_flags(cx, v, ptr, labels)
705-
case Own() : store_int(cx, lower_own(opts, v, t), ptr, 4)
706-
case Borrow() : store_int(cx, lower_borrow(opts, v, t), ptr, 4)
704+
case Own() : store_int(cx, lower_own(cx.opts, v, t), ptr, 4)
705+
case Borrow() : store_int(cx, lower_borrow(cx.opts, v, t), ptr, 4)
707706
```
708707

709708
Integers are stored directly into memory. Because the input domain is exactly
@@ -1195,7 +1194,7 @@ class Value:
11951194

11961195
@dataclass
11971196
class ValueIter:
1198-
values: [Value]
1197+
values: list[Value]
11991198
i = 0
12001199
def next(self, t):
12011200
v = self.values[self.i]

design/mvp/canonical-abi/definitions.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ class CoreExportDecl:
4141

4242
@dataclass
4343
class ModuleType(ExternType):
44-
imports: [CoreImportDecl]
45-
exports: [CoreExportDecl]
44+
imports: list[CoreImportDecl]
45+
exports: list[CoreExportDecl]
4646

4747
@dataclass
4848
class CoreFuncType(CoreExternType):
49-
params: [str]
50-
results: [str]
49+
params: list[str]
50+
results: list[str]
5151

5252
@dataclass
5353
class CoreMemoryType(CoreExternType):
54-
initial: [int]
54+
initial: list[int]
5555
maximum: Optional[int]
5656

5757
@dataclass
@@ -61,17 +61,17 @@ class ExternDecl:
6161

6262
@dataclass
6363
class ComponentType(ExternType):
64-
imports: [ExternDecl]
65-
exports: [ExternDecl]
64+
imports: list[ExternDecl]
65+
exports: list[ExternDecl]
6666

6767
@dataclass
6868
class InstanceType(ExternType):
69-
exports: [ExternDecl]
69+
exports: list[ExternDecl]
7070

7171
@dataclass
7272
class FuncType(ExternType):
73-
params: [typing.Tuple[str,ValType]]
74-
results: [ValType|typing.Tuple[str,ValType]]
73+
params: list[tuple[str,ValType]]
74+
results: list[ValType|tuple[str,ValType]]
7575
def param_types(self):
7676
return self.extract_types(self.params)
7777
def result_types(self):
@@ -122,25 +122,25 @@ class Field:
122122

123123
@dataclass
124124
class Record(ValType):
125-
fields: [Field]
125+
fields: list[Field]
126126

127127
@dataclass
128128
class Tuple(ValType):
129-
ts: [ValType]
129+
ts: list[ValType]
130130

131131
@dataclass
132132
class Case:
133133
label: str
134134
t: Optional[ValType]
135-
refines: str = None
135+
refines: Optional[str] = None
136136

137137
@dataclass
138138
class Variant(ValType):
139-
cases: [Case]
139+
cases: list[Case]
140140

141141
@dataclass
142142
class Enum(ValType):
143-
labels: [str]
143+
labels: list[str]
144144

145145
@dataclass
146146
class Option(ValType):
@@ -153,7 +153,7 @@ class Result(ValType):
153153

154154
@dataclass
155155
class Flags(ValType):
156-
labels: [str]
156+
labels: list[str]
157157

158158
@dataclass
159159
class Own(ValType):
@@ -276,7 +276,7 @@ def num_i32_flags(labels):
276276
class CallContext:
277277
opts: CanonicalOptions
278278
inst: ComponentInstance
279-
lenders: [HandleElem]
279+
lenders: list[HandleElem]
280280
borrow_count: int
281281

282282
def __init__(self, opts, inst):
@@ -332,8 +332,8 @@ def __init__(self, rep, own, scope = None):
332332
self.lend_count = 0
333333

334334
class HandleTable:
335-
array: [Optional[HandleElem]]
336-
free: [int]
335+
array: list[Optional[HandleElem]]
336+
free: list[int]
337337

338338
def __init__(self):
339339
self.array = [None]
@@ -402,8 +402,8 @@ def load(cx, ptr, t):
402402
case Record(fields) : return load_record(cx, ptr, fields)
403403
case Variant(cases) : return load_variant(cx, ptr, cases)
404404
case Flags(labels) : return load_flags(cx, ptr, labels)
405-
case Own() : return lift_own(cx, load_int(opts, ptr, 4), t)
406-
case Borrow() : return lift_borrow(cx, load_int(opts, ptr, 4), t)
405+
case Own() : return lift_own(cx, load_int(cx.opts, ptr, 4), t)
406+
case Borrow() : return lift_borrow(cx, load_int(cx.opts, ptr, 4), t)
407407

408408
def load_int(cx, ptr, nbytes, signed = False):
409409
return int.from_bytes(cx.opts.memory[ptr : ptr+nbytes], 'little', signed=signed)
@@ -573,8 +573,8 @@ def store(cx, v, t, ptr):
573573
case Record(fields) : store_record(cx, v, ptr, fields)
574574
case Variant(cases) : store_variant(cx, v, ptr, cases)
575575
case Flags(labels) : store_flags(cx, v, ptr, labels)
576-
case Own() : store_int(cx, lower_own(opts, v, t), ptr, 4)
577-
case Borrow() : store_int(cx, lower_borrow(opts, v, t), ptr, 4)
576+
case Own() : store_int(cx, lower_own(cx.opts, v, t), ptr, 4)
577+
case Borrow() : store_int(cx, lower_borrow(cx.opts, v, t), ptr, 4)
578578

579579
def store_int(cx, v, ptr, nbytes, signed = False):
580580
cx.opts.memory[ptr : ptr+nbytes] = int.to_bytes(v, nbytes, 'little', signed=signed)
@@ -897,7 +897,7 @@ class Value:
897897

898898
@dataclass
899899
class ValueIter:
900-
values: [Value]
900+
values: list[Value]
901901
i = 0
902902
def next(self, t):
903903
v = self.values[self.i]

0 commit comments

Comments
 (0)