# HG changeset patch # User Paul Boddie # Date 1308006405 -7200 # Node ID 1964e5898e68087e5d929f11ee84e1812e93a6dc # Parent dced8cb98f4a3c414ea1f8a5aa9269543bfe5d3e Fixed negation of operator method results in other operator methods. Added NotImplementedType as an automatically generated class. diff -r dced8cb98f4a -r 1964e5898e68 lib/builtins.py --- a/lib/builtins.py Mon Jun 13 20:59:00 2011 +0200 +++ b/lib/builtins.py Tue Jun 14 01:06:45 2011 +0200 @@ -35,7 +35,9 @@ def __init__(self): "No-operation." pass - def __bool__(self): pass + def __bool__(self): + "Objects are true by default." + return True class basestring(object): def __init__(self, x=None): pass @@ -68,11 +70,11 @@ def __le__(self, other): "Return a new boolean for the comparison." - return not self.__gt__(other) + return _negate(self.__gt__(other)) def __ge__(self, other): "Return a new boolean for the comparison." - return not self.__lt__(other) + return _negate(self.__lt__(other)) def __eq__(self, other): "Return a new boolean for the comparison." @@ -80,13 +82,13 @@ def __ne__(self, other): "Return a new boolean for the comparison." - return not self.__eq__(other) + return _negate(self.__eq__(other)) def __len__(self): pass def __str__(self): pass def __bool__(self): - return not native._str_eq(self, "") + return _negate(native._str_eq(self, "")) def join(self, l): pass def split(self, s): pass @@ -237,11 +239,11 @@ def __le__(self, other): "Return a new boolean for the comparison." - return not self.__gt__(other) + return _negate(self.__gt__(other)) def __ge__(self, other): "Return a new boolean for the comparison." - return not self.__lt__(other) + return _negate(self.__lt__(other)) def __eq__(self, other): "Return a new boolean for the comparison." @@ -249,7 +251,7 @@ def __ne__(self, other): "Return a new boolean for the comparison." - return not self.__eq__(other) + return _negate(self.__eq__(other)) def __neg__(self): pass def __pos__(self): pass @@ -261,7 +263,7 @@ def __bool__(self): "Return whether this int is non-zero." - return not native._int_eq(self, 0) + return _negate(native._int_eq(self, 0)) class list(object): @@ -673,6 +675,15 @@ else: return NotImplemented +def _negate(result): + + "Negate any valid logical value." + + if result is NotImplemented: + return result + else: + return not result + def _get_absolute_index(index, length): """ @@ -769,7 +780,7 @@ AttributeError #IndexError #NoneType -#NotImplementedType +NotImplementedType #StopIteration TypeError diff -r dced8cb98f4a -r 1964e5898e68 micropython/inspect.py --- a/micropython/inspect.py Mon Jun 13 20:59:00 2011 +0200 +++ b/micropython/inspect.py Tue Jun 14 01:06:45 2011 +0200 @@ -658,7 +658,6 @@ # NOTE: this is merely creating aliases for such methods. self.use_specific_attribute(None, node.name) - return None visitAssTuple = visitAssList diff -r dced8cb98f4a -r 1964e5898e68 tests/compare_equality.py --- a/tests/compare_equality.py Mon Jun 13 20:59:00 2011 +0200 +++ b/tests/compare_equality.py Tue Jun 14 01:06:45 2011 +0200 @@ -14,6 +14,7 @@ result_1 = 0 result_2 = 2 result_3 = 3 +result_4 = 0 if a != x != b: result_1 = 1 @@ -24,4 +25,7 @@ if a == x: result_3 = 0 +if a != x: + result_4 = 4 + # vim: tabstop=4 expandtab shiftwidth=4