Skip to content

Commit b3c0053

Browse files
authored
only emit python annotated assigns when definition (microsoft#11257)
1 parent 382c530 commit b3c0053

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

‎pxtpy/converter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ namespace pxt.py {
18821882
}
18831883

18841884
let lExp: B.JsNode | undefined = undefined;
1885-
if (annotation && annotAsType) {
1885+
if (annotation && annotAsType && target.kind === "Name" && (target as py.Name).isdef) {
18861886
// if we have a type annotation, emit it in these cases if the r-value is:
18871887
// - null / undefined
18881888
// - empty list
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Foo {
2+
l: Bar[]
3+
constructor() {
4+
this.l = []
5+
}
6+
7+
}
8+
9+
class Bar {
10+
constructor() {
11+
12+
}
13+
14+
}
15+
16+
let foo = 9
17+
foo = 8
18+
let bar : Bar = null
19+
bar = null
20+
let bop : number[] = []
21+
bop = []
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Foo:
2+
def __init__(self):
3+
self.l: List[Bar] = []
4+
5+
class Bar:
6+
def __init__(self):
7+
pass
8+
9+
foo: number = 9
10+
foo: number = 8
11+
12+
bar: Bar = None
13+
bar: Bar = None
14+
15+
bop: List[number] = []
16+
bop: List[number] = []

0 commit comments

Comments
 (0)