On Sat, Dec 27, 2008 at 7:45 PM, Armin Rigo <[email protected]> wrote:
>
> You can try, but it's messy. It's not a problem for the annotator but
> for the later RTyper. None is implemented as a NULL pointer by the
Atatched is a small patch for the annotator that makes it treat None
and NotImplemented alike. This is all that is needed for most cases as
all NotImplemented are typically removed by the optimisations
performed by the annotator.
At http://hakan.ardoe.net/pypy/ I have placed special_methods.py that
adds support for the methods listed below together with 42 test
including the relevant parts of test_augassign.py and test_binop.py
from the cpython source (somewhat modified to work). The methods
currently supported are:
__str__, __repr__, __len__, __getitem__, __setitem__, __add__,
__mul__, __sub__, __div__, __floordiv__, __mod__, __xor__, __rshift__,
__lshift__, __radd__, __rmul__, __rsub__, __rdiv__, __rfloordiv__,
__rmod__, __rxor__, __rrshift__, __rlshift__, __iadd__, __imul__,
__isub__, __idiv__, __ifloordiv__, __imod__, __ixor__, __irshift__,
__ilshift__
With this implementation, the opperation str(o) calls o.__str__(), but
the opperation "%s"%o does not. I don't know why.
--
Håkan Ardö
Index: pypy/annotation/model.py
===================================================================
--- pypy/annotation/model.py (revision 60718)
+++ pypy/annotation/model.py (working copy)
@@ -150,6 +150,12 @@
def nonnoneify(self):
return self
+ def can_be_notImplemented(self):
+ if self.__class__ is SomeObject:
+ return True
+ else:
+ return False
+
class SomeFloat(SomeObject):
"Stands for a float or an integer."
knowntype = float # if we don't know if it's a float or an int,
Index: pypy/annotation/binaryop.py
===================================================================
--- pypy/annotation/binaryop.py (revision 60718)
+++ pypy/annotation/binaryop.py (working copy)
@@ -173,9 +173,13 @@
r.const = obj1.const is obj2.const
if obj2.const is None and not obj1.can_be_none():
r.const = False
+ if obj2.const is NotImplemented and not obj1.can_be_notImplemented():
+ r.const = False
elif obj1.is_constant():
if obj1.const is None and not obj2.can_be_none():
r.const = False
+ if obj2.const is NotImplemented and not obj1.can_be_notImplemented():
+ r.const = False
# XXX HACK HACK HACK
# XXX HACK HACK HACK
# XXX HACK HACK HACK
_______________________________________________
[email protected]
http://codespeak.net/mailman/listinfo/pypy-dev