[pypy-svn] r7714 - pypy/trunk/src/pypy/annotation
arigo at codespeak.net
arigo at codespeak.net
Tue Nov 30 15:41:46 CET 2004
Author: arigo
Date: Tue Nov 30 15:41:46 2004
New Revision: 7714
Modified:
pypy/trunk/src/pypy/annotation/bookkeeper.py
pypy/trunk/src/pypy/annotation/unaryop.py
Log:
Trying to get rid of a hack: look for method_xxx() on SomeXxx objects from
immutablevalue().
Modified: pypy/trunk/src/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/bookkeeper.py (original)
+++ pypy/trunk/src/pypy/annotation/bookkeeper.py Tue Nov 30 15:41:46 2004
@@ -99,10 +99,10 @@
x.im_self.freeze()
if hasattr(x, '__self__') and x.__self__ is not None:
s_self = self.immutablevalue(x.__self__)
- # stop infinite recursion getattr<->immutablevalue
- del s_self.const
- s_name = self.immutablevalue(x.__name__)
- result = s_self.getattr(s_name)
+ try:
+ result = s_self.find_method(x.__name__)
+ except AttributeError:
+ result = SomeObject()
else:
return self.getpbc(x)
elif hasattr(x, '__class__') \
Modified: pypy/trunk/src/pypy/annotation/unaryop.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/unaryop.py (original)
+++ pypy/trunk/src/pypy/annotation/unaryop.py Tue Nov 30 15:41:46 2004
@@ -40,14 +40,20 @@
else:
return SomeBool()
+ def find_method(obj, name):
+ "Look for a special-case implementation for the named method."
+ analyser = getattr(obj.__class__, 'method_' + name)
+ return SomeBuiltin(analyser, obj)
+
def getattr(obj, s_attr):
# get a SomeBuiltin if the SomeObject has
# a corresponding method to handle it
if s_attr.is_constant() and isinstance(s_attr.const, str):
attr = s_attr.const
- analyser = getattr(obj.__class__, 'method_' + attr, None)
- if analyser is not None:
- return SomeBuiltin(analyser, obj)
+ try:
+ return obj.find_method(attr)
+ except AttributeError:
+ pass
# if the SomeObject is itself a constant, allow reading its attrs
if obj.is_constant() and hasattr(obj.const, attr):
return immutablevalue(getattr(obj.const, attr))
More information about the Pypy-commit
mailing list