mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 10:49:54 +00:00
27 lines
542 B
Python
27 lines
542 B
Python
i: Int = 2 - 1
|
|
assert i in Nat
|
|
i: Nat
|
|
assert i in Str # ERR, i cannot be of type Str
|
|
|
|
f(opt_i: Int or NoneType) =
|
|
if opt_i != None, do:
|
|
if opt_i >= 0, do:
|
|
log opt_i.times!
|
|
log opt_i + 1 # OK
|
|
log opt_i.times! # ERR
|
|
if isinstance(opt_i, Int), do:
|
|
log opt_i + 1 # OK
|
|
log opt_i + 1 # ERR
|
|
|
|
f(1)
|
|
|
|
json = pyimport "json"
|
|
s = "{ \"key\": \"value\" }"
|
|
jdata = json.loads(s)
|
|
assert jdata in {Str: Str}
|
|
assert jdata["key"] == "value"
|
|
|
|
is_int(x: Obj) = x in Int
|
|
y as Obj = 1
|
|
assert is_int y
|
|
y: Int
|