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:
Paul Sokolovsky
2014-01-30 04:37:19 +02:00
parent cdd2c62e07
commit c1d9bbc345
13 changed files with 52 additions and 16 deletions

View File

@@ -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":