Skip to content

Commit 7b39b2d

Browse files
committed
fix(py),feat(sugar): := did never declare variable.
1 parent 34ec7db commit 7b39b2d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/pylib/pysugar.nim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ template pass* = discard
2121
template lambda*(code: untyped): untyped =
2222
(proc (): auto = code) # Mimic Pythons Lambda
2323

24-
template `:=`*(name, value: untyped): untyped =
24+
template `:=`*[T](name; value: T): T =
2525
## Mimic Pythons Operator.
26-
## Creates new variable `name` and assign `value` to it.
27-
(var name = value; name)
26+
when not declared(name):
27+
var name: T
28+
name = value
29+
name
2830

2931
macro del*(seqIdx: untyped) =
3032
##[

0 commit comments

Comments
 (0)