[pypy-svn] r20150 - in pypy/branch/somepbc-refactoring/pypy: annotation translator/test
pedronis at codespeak.net
pedronis at codespeak.net
Mon Nov 21 23:19:35 CET 2005
Author: pedronis
Date: Mon Nov 21 23:19:32 2005
New Revision: 20150
Modified:
pypy/branch/somepbc-refactoring/pypy/annotation/bookkeeper.py
pypy/branch/somepbc-refactoring/pypy/annotation/description.py
pypy/branch/somepbc-refactoring/pypy/annotation/unaryop.py
pypy/branch/somepbc-refactoring/pypy/translator/test/test_annrpython.py
Log:
always attach a method name to MethodDescs.
Modified: pypy/branch/somepbc-refactoring/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/bookkeeper.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/bookkeeper.py Mon Nov 21 23:19:32 2005
@@ -3,7 +3,7 @@
"""
from __future__ import generators
-import sys, types
+import sys, types, inspect
from pypy.objspace.flow.model import Constant
from pypy.annotation.model import SomeString, SomeChar, SomeFloat, \
@@ -369,7 +369,8 @@
else: # regular method
result = self.getmethoddesc(
self.getdesc(pyobj.im_func), # funcdesc
- self.getuniqueclassdef(pyobj.im_class)) # classdef
+ self.getuniqueclassdef(pyobj.im_class), # classdef
+ name_of_meth(pyobj))
else:
# must be a frozen pre-built constant, but let's check
assert pyobj._freeze_()
@@ -384,12 +385,12 @@
self.descs[pyobj] = result
return result
- def getmethoddesc(self, funcdesc, classdef):
+ def getmethoddesc(self, funcdesc, classdef, name):
try:
- return self.methoddescs[funcdesc, classdef]
+ return self.methoddescs[funcdesc, classdef, name]
except KeyError:
- result = description.MethodDesc(self, funcdesc, classdef)
- self.methoddescs[funcdesc, classdef] = result
+ result = description.MethodDesc(self, funcdesc, classdef, name)
+ self.methoddescs[funcdesc, classdef, name] = result
return result
def valueoftype(self, t):
@@ -520,6 +521,18 @@
def warning(self, msg):
return self.annotator.warning(msg)
+def name_of_meth(boundmeth):
+ func = boundmeth.im_func
+ candname = func.func_name
+ for cls in inspect.getmro(boundmeth.im_class):
+ dict = cls.__dict__
+ if dict.get(candname) is func:
+ return candname
+ for name, value in dict.iteritems():
+ if value is func:
+ return name
+ raise Exception, "could not match bound-method to attribute name: %r" % (boundmeth,)
+
def ishashable(x):
try:
hash(x)
Modified: pypy/branch/somepbc-refactoring/pypy/annotation/description.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/description.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/description.py Mon Nov 21 23:19:32 2005
@@ -80,7 +80,7 @@
changed = changed or changed1
return changed
- def bind(self, classdef):
+ def bind_under(self, classdef, name):
return self
@@ -148,9 +148,9 @@
result = unionof(result, s_previous_result)
return result
- def bind(self, classdef):
+ def bind_under(self, classdef, name):
# XXX static methods
- return self.bookkeeper.getmethoddesc(self, classdef)
+ return self.bookkeeper.getmethoddesc(self, classdef, name)
class ClassDesc(Desc):
@@ -300,11 +300,11 @@
if isinstance(obj, Constant):
s_value = self.bookkeeper.immutablevalue(obj.value)
if classdef is not None:
- s_value = s_value.bindcallables(classdef)
+ s_value = s_value.bind_callables_under(classdef, name)
elif isinstance(obj, Desc):
from pypy.annotation.model import SomePBC
if classdef is not None:
- obj = obj.bind(classdef)
+ obj = obj.bind_under(classdef, name)
s_value = SomePBC([obj])
else:
raise TypeError("classdict should not contain %r" % (obj,))
@@ -326,10 +326,11 @@
class MethodDesc(Desc):
knowntype = types.MethodType
- def __init__(self, bookkeeper, funcdesc, classdef):
+ def __init__(self, bookkeeper, funcdesc, classdef, name):
super(MethodDesc, self).__init__(bookkeeper)
self.funcdesc = funcdesc
self.classdef = classdef
+ self.name = name
def __repr__(self):
return '<MethodDesc %r of %r>' % (self.funcdesc,
@@ -341,9 +342,9 @@
args = args.prepend(s_instance)
return self.funcdesc.pycall(schedule, args, s_previous_result)
- def bind(self, classdef):
+ def bind_under(self, classdef, name):
self.bookkeeper.warning("rebinding an already bound %r" % (self,))
- return self.funcdesc.bind(classdef)
+ return self.funcdesc.bind_under(classdef, name)
def new_or_old_class(c):
Modified: pypy/branch/somepbc-refactoring/pypy/annotation/unaryop.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/unaryop.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/unaryop.py Mon Nov 21 23:19:32 2005
@@ -159,7 +159,7 @@
return SomeObject()
getattr.can_only_throw = []
- def bindcallables(obj, classdef):
+ def bind_callables_under(obj, classdef, name):
return obj # default unbound __get__ implementation
def simple_call(obj, *args_s):
@@ -508,8 +508,8 @@
bookkeeper = getbookkeeper()
return bookkeeper.pbc_call(pbc, args)
- def bindcallables(pbc, classdef):
- d = [desc.bind(classdef) for desc in pbc.descriptions]
+ def bind_callables_under(pbc, classdef, name):
+ d = [desc.bind_under(classdef, name) for desc in pbc.descriptions]
return SomePBC(d, can_be_None=pbc.can_be_None)
def is_true_behavior(pbc):
Modified: pypy/branch/somepbc-refactoring/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/translator/test/test_annrpython.py (original)
+++ pypy/branch/somepbc-refactoring/pypy/translator/test/test_annrpython.py Mon Nov 21 23:19:32 2005
@@ -905,7 +905,9 @@
bookkeeper = a.bookkeeper
def fam(meth):
- mdesc = bookkeeper.getmethoddesc(bookkeeper.getdesc(meth.im_func), clsdef(meth.im_class))
+ mdesc = bookkeeper.getmethoddesc(bookkeeper.getdesc(meth.im_func), clsdef(meth.im_class), meth.im_func.func_name)
+ mdesc2 = bookkeeper.immutablevalue(meth.im_func.__get__(meth.im_class(), meth.im_class)).descriptions.keys()[0]
+ assert mdesc == mdesc2 # sanity check
return mdesc.getcallfamily()
famA_m = fam(A.m)
More information about the Pypy-commit
mailing list