mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 12:40:15 +01:00
py/native: Improve support for bool type in viper functions.
Variables with type bool now act more like an int, and there is proper casting to/from Python objects.
This commit is contained in:
26
tests/micropython/viper_types.py
Normal file
26
tests/micropython/viper_types.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# test various type conversions
|
||||
|
||||
import micropython
|
||||
|
||||
# converting incoming arg to bool
|
||||
@micropython.viper
|
||||
def f1(x:bool):
|
||||
print(x)
|
||||
f1(0)
|
||||
f1(1)
|
||||
f1([])
|
||||
f1([1])
|
||||
|
||||
# taking and returning a bool
|
||||
@micropython.viper
|
||||
def f2(x:bool) -> bool:
|
||||
return x
|
||||
print(f2([]))
|
||||
print(f2([1]))
|
||||
|
||||
# converting to bool within function
|
||||
@micropython.viper
|
||||
def f3(x) -> bool:
|
||||
return bool(x)
|
||||
print(f3([]))
|
||||
print(f3(-1))
|
||||
8
tests/micropython/viper_types.py.exp
Normal file
8
tests/micropython/viper_types.py.exp
Normal file
@@ -0,0 +1,8 @@
|
||||
False
|
||||
True
|
||||
False
|
||||
True
|
||||
False
|
||||
True
|
||||
False
|
||||
True
|
||||
Reference in New Issue
Block a user