mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 04:30:24 +01:00
Implement __bool__ and __len__ via unary_op virtual method for all types.
__bool__() and __len__() are just the same as __neg__() or __invert__(), and require efficient dispatching implementation (not requiring search/lookup). type->unary_op() is just the right choice for this short of adding standalone virtual method(s) to already big mp_obj_type_t structure.
This commit is contained in:
@@ -3,9 +3,18 @@
|
||||
if not False:
|
||||
print("False")
|
||||
|
||||
if not None:
|
||||
print("None")
|
||||
|
||||
if not 0:
|
||||
print("0")
|
||||
|
||||
if not 0.0:
|
||||
print("float 0")
|
||||
|
||||
if not 0+0j:
|
||||
print("complex 0")
|
||||
|
||||
if not "":
|
||||
print("Empty string")
|
||||
if "foo":
|
||||
|
||||
Reference in New Issue
Block a user