mirror of
https://github.com/erg-lang/erg.git
synced 2025-07-07 21:25:31 +00:00
33 lines
664 B
Python
33 lines
664 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
|
|
|
|
bs x: Bytes or Str =
|
|
discard if not(isinstance(x, Str)), do:
|
|
# x: Bytes
|
|
str(x, "ascii")
|
|
_ = bs "abc"
|