Author: Ronan Lamy <ronan.l...@gmail.com> Branch: online-transforms Changeset: r74208:e768de5dd66a Date: 2014-10-25 14:57 +0200 http://bitbucket.org/pypy/pypy/changeset/e768de5dd66a/
Log: fix some nonsense with other nonsense diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py --- a/rpython/annotator/bookkeeper.py +++ b/rpython/annotator/bookkeeper.py @@ -362,6 +362,10 @@ # * a frozen pre-built constant (with _freeze_() == True) # * a bound method of a frozen pre-built constant try: + pyobj = normalize_method(pyobj) + except ValueError: + pass + try: return self.descs[pyobj] except KeyError: if is_user_function(pyobj): diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py --- a/rpython/annotator/description.py +++ b/rpython/annotator/description.py @@ -7,6 +7,7 @@ from rpython.tool.sourcetools import valid_identifier, func_with_new_name from rpython.tool.pairtype import extendabletype from rpython.annotator.model import AnnotatorError +from rpython.tool.descriptor import normalize_method class CallFamily(object): """A family of Desc objects that could be called from common call sites. @@ -516,7 +517,10 @@ # pretend that built-in exceptions have no __init__, # unless explicitly specified in builtin.py from rpython.annotator.builtin import BUILTIN_ANALYZERS - value = getattr(value, 'im_func', value) + try: + value = normalize_method(value) + except ValueError: + pass if value not in BUILTIN_ANALYZERS: return self.classdict[name] = Constant(value) diff --git a/rpython/rtyper/rbuiltin.py b/rpython/rtyper/rbuiltin.py --- a/rpython/rtyper/rbuiltin.py +++ b/rpython/rtyper/rbuiltin.py @@ -7,6 +7,7 @@ from rpython.rtyper import rclass from rpython.rtyper.rmodel import Repr from rpython.tool.pairtype import pairtype +from rpython.tool.descriptor import normalize_method BUILTIN_TYPER = {} @@ -276,13 +277,12 @@ return hop.r_result.newiter(hop) -@typer_for(getattr(object.__init__, 'im_func', object.__init__)) +@typer_for(normalize_method(object.__init__)) def rtype_object__init__(hop): hop.exception_cannot_occur() -@typer_for(getattr(EnvironmentError.__init__, 'im_func', - EnvironmentError.__init__)) +@typer_for(normalize_method(EnvironmentError.__init__)) def rtype_EnvironmentError__init__(hop): hop.exception_cannot_occur() v_self = hop.args_v[0] @@ -306,8 +306,7 @@ except NameError: pass else: - @typer_for( - getattr(WindowsError.__init__, 'im_func', WindowsError.__init__)) + @typer_for(normalize_method(WindowsError.__init__)) def rtype_WindowsError__init__(hop): hop.exception_cannot_occur() if hop.nb_args == 2: diff --git a/rpython/tool/descriptor.py b/rpython/tool/descriptor.py --- a/rpython/tool/descriptor.py +++ b/rpython/tool/descriptor.py @@ -36,8 +36,10 @@ if '__pypy__' in sys.modules: def normalize_method(method): - '''Turn everything that behaves like a method into an InstanceMethod object''' + '''Turn everything that behaves like a method into a regular function or an InstanceMethod object''' if isinstance(method, types.MethodType): + if method.__self__ is None: + return method.im_func return InstanceMethod(method.__func__, method.__self__, method.im_class) else: raise ValueError('Not a method') @@ -48,8 +50,10 @@ method_descriptor = type(str.join) def normalize_method(method): - '''Turn everything that behaves like a method into an InstanceMethod object''' + '''Turn everything that behaves like a method into a regular function or an InstanceMethod object''' if isinstance(method, types.MethodType): + if method.__self__ is None: + return method.__func__ return InstanceMethod(method.__func__, method.__self__, method.im_class) elif isinstance(method, types.BuiltinMethodType): im_self = method.__self__ _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit