# HG changeset patch # User paulb@localhost.localdomain # Date 1169771188 -3600 # Node ID bb09a8becf0160d672b6086203f7d56b010f10c2 # Parent bcff64bc6ffaba6da00be14f5154a61ca5748175 Made comparable nodes support alternative __eq__ tests. Added NotImplemented value and NotImplementedType to the builtins. Updated the operators test. diff -r bcff64bc6ffa -r bb09a8becf01 lib/builtins.py --- a/lib/builtins.py Fri Jan 26 00:05:20 2007 +0100 +++ b/lib/builtins.py Fri Jan 26 01:26:28 2007 +0100 @@ -218,7 +218,7 @@ elif isinstance(other, float): return bool() else: - raise TypeError + return NotImplemented def __gt__(self, other): if isinstance(other, int): @@ -228,7 +228,7 @@ elif isinstance(other, float): return bool() else: - raise TypeError + return NotImplemented def __le__(self, other): if isinstance(other, int): @@ -238,7 +238,7 @@ elif isinstance(other, float): return bool() else: - raise TypeError + return NotImplemented def __ge__(self, other): if isinstance(other, int): @@ -248,7 +248,7 @@ elif isinstance(other, float): return bool() else: - raise TypeError + return NotImplemented def __eq__(self, other): if isinstance(other, int): @@ -258,7 +258,7 @@ elif isinstance(other, float): return bool() else: - raise TypeError + return NotImplemented def __ne__(self, other): if isinstance(other, int): @@ -268,7 +268,7 @@ elif isinstance(other, float): return bool() else: - raise TypeError + return NotImplemented def __neg__(self): return float() @@ -365,37 +365,37 @@ if isinstance(other, int): return bool() else: - raise TypeError + return NotImplemented def __gt__(self, other): if isinstance(other, int): return bool() else: - raise TypeError + return NotImplemented def __le__(self, other): if isinstance(other, int): return bool() else: - raise TypeError + return NotImplemented def __ge__(self, other): if isinstance(other, int): return bool() else: - raise TypeError + return NotImplemented def __eq__(self, other): if isinstance(other, int): return bool() else: - raise TypeError + return NotImplemented def __ne__(self, other): if isinstance(other, int): return bool() else: - raise TypeError + return NotImplemented def __neg__(self): return int() @@ -531,7 +531,7 @@ elif isinstance(other, long): return bool() else: - raise TypeError + return NotImplemented def __gt__(self, other): if isinstance(other, int): @@ -539,7 +539,7 @@ elif isinstance(other, long): return bool() else: - raise TypeError + return NotImplemented def __le__(self, other): if isinstance(other, int): @@ -547,7 +547,7 @@ elif isinstance(other, long): return bool() else: - raise TypeError + return NotImplemented def __ge__(self, other): if isinstance(other, int): @@ -555,7 +555,7 @@ elif isinstance(other, long): return bool() else: - raise TypeError + return NotImplemented def __eq__(self, other): if isinstance(other, int): @@ -563,7 +563,7 @@ elif isinstance(other, long): return bool() else: - raise TypeError + return NotImplemented def __ne__(self, other): if isinstance(other, int): @@ -571,7 +571,7 @@ elif isinstance(other, long): return bool() else: - raise TypeError + return NotImplemented def __neg__(self): return long() @@ -736,6 +736,9 @@ class TypeError(Exception): pass +class NotImplementedType: + pass + # General functions. def isinstance(obj, cls): @@ -782,6 +785,7 @@ stdin = file() stdout = file() stderr = file() +NotImplemented = NotImplementedType() # Special functions. These all operate on references at run-time. diff -r bcff64bc6ffa -r bb09a8becf01 simplified.py --- a/simplified.py Fri Jan 26 00:05:20 2007 +0100 +++ b/simplified.py Fri Jan 26 01:26:28 2007 +0100 @@ -476,7 +476,10 @@ def __eq__(self, other): # NOTE: Single instance: all instances are the same # NOTE: Multiple instances: all instances are different - return self.full_name() == other.full_name() + if hasattr(other, "full_name"): + return self.full_name() == other.full_name() + else: + return NotImplemented def __hash__(self): return id(self) diff -r bcff64bc6ffa -r bb09a8becf01 tests/operators.py --- a/tests/operators.py Fri Jan 26 00:05:20 2007 +0100 +++ b/tests/operators.py Fri Jan 26 01:26:28 2007 +0100 @@ -1,5 +1,8 @@ -a = 1 + 1.1 - 1 -b = a + 2 / 2 -c = -a -d = +b -e = a // b +def f(): + a = 1 + 1.1 - 1 + b = a + 2 / 2 + c = -a + d = +b + e = a // b + +f()