[pypy-svn] r7351 - in pypy/trunk/src/pypy: annotation objspace/std
bob at codespeak.net
bob at codespeak.net
Wed Nov 17 19:25:59 CET 2004
Author: bob
Date: Wed Nov 17 19:25:56 2004
New Revision: 7351
Modified:
pypy/trunk/src/pypy/annotation/model.py
pypy/trunk/src/pypy/annotation/unaryop.py
pypy/trunk/src/pypy/objspace/std/multimethod.py
Log:
hack to analyze builtin methods
Modified: pypy/trunk/src/pypy/annotation/model.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/model.py (original)
+++ pypy/trunk/src/pypy/annotation/model.py Wed Nov 17 19:25:56 2004
@@ -34,7 +34,6 @@
from pypy.annotation.pairtype import pair, extendabletype
from pypy.objspace.flow.model import Constant
-
class SomeObject:
"""The set of all objects. Each instance stands
for an arbitrary object about which nothing is known."""
@@ -138,7 +137,7 @@
# callables is a dictionary containing concrete python
# callable objects as keys and - in the case of a method -
# the value contains the classdef (see SomeMethod above)
- self.callables = callables
+ self.callables = callables
if len(callables) == 1:
self.const, = callables
@@ -207,8 +206,13 @@
result = SomeTuple(items = [immutablevalue(e) for e in x])
elif ishashable(x) and x in BUILTIN_FUNCTIONS:
result = SomeBuiltin(BUILTIN_FUNCTIONS[x])
- elif callable(x):
- result = SomeCallable({x : True})
+ elif callable(x):
+ if hasattr(x, '__self__') and x.__self__ is not None:
+ x_self = immutablevalue(x.__self__)
+ x_name = immutablevalue(x.__name__)
+ result = x_self.getattr(x_name, hack=True)
+ else:
+ result = SomeCallable({x : True})
elif hasattr(x, '__class__') and x.__class__.__module__ != '__builtin__':
result = SomePrebuiltConstant({x: True}) # pre-built inst:
else:
Modified: pypy/trunk/src/pypy/annotation/unaryop.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/unaryop.py (original)
+++ pypy/trunk/src/pypy/annotation/unaryop.py Wed Nov 17 19:25:56 2004
@@ -38,7 +38,7 @@
else:
return SomeBool()
- def getattr(obj, s_attr):
+ def getattr(obj, s_attr, hack=False):
# get a SomeBuiltin if the SomeObject has
# a corresponding method to handle it
if s_attr.is_constant() and isinstance(s_attr.const, str):
@@ -47,7 +47,7 @@
if analyser is not None:
return SomeBuiltin(analyser, obj)
# if the SomeObject is itself a constant, allow reading its attrs
- if obj.is_constant() and hasattr(obj.const, attr):
+ if not hack and obj.is_constant() and hasattr(obj.const, attr):
return immutablevalue(getattr(obj.const, attr))
return SomeObject()
@@ -164,7 +164,7 @@
""" turn the callables in the given SomeCallable 'cal'
into bound versions.
"""
- d = {}
+ d = cal.callables.copy()
for func, value in cal.callables.items():
if isinstance(func, FunctionType):
if isclassdef(value):
Modified: pypy/trunk/src/pypy/objspace/std/multimethod.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/multimethod.py (original)
+++ pypy/trunk/src/pypy/objspace/std/multimethod.py Wed Nov 17 19:25:56 2004
@@ -1,4 +1,5 @@
from pypy.interpreter.baseobjspace import OperationError
+from pypy.tool.frozendict import frozendict
class FailedToImplement(Exception):
@@ -61,6 +62,7 @@
try:
return self.cache_table[argclasses]
except KeyError:
+ assert not isinstance(self.cache_table, frozendict)
calllist = []
self.internal_buildcalllist(argclasses, delegate, calllist)
result = self.internal_compilecalllist(argclasses, calllist)
More information about the Pypy-commit
mailing list