[pypy-commit] pypy online-transforms: Simplify use of normalize_method(): return non-methods unchanged

rlamy noreply at buildbot.pypy.org
Thu Nov 6 17:43:42 CET 2014


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: online-transforms
Changeset: r74354:a98b25085355
Date: 2014-11-06 03:59 +0000
http://bitbucket.org/pypy/pypy/changeset/a98b25085355/

Log:	Simplify use of normalize_method(): return non-methods unchanged

diff --git a/rpython/annotator/bookkeeper.py b/rpython/annotator/bookkeeper.py
--- a/rpython/annotator/bookkeeper.py
+++ b/rpython/annotator/bookkeeper.py
@@ -231,10 +231,7 @@
         """The most precise SomeValue instance that contains the
         immutable value x."""
         if callable(x):
-            try:
-                x = normalize_method(x)
-            except ValueError:
-                pass
+            x = normalize_method(x)
         tp = type(x)
         if issubclass(tp, Symbolic): # symbolic constants support
             result = x.annotation()
@@ -372,10 +369,7 @@
         #  * a user-defined bound or unbound method object
         #  * 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
+        pyobj = normalize_method(pyobj)
         try:
             return self.descs[pyobj]
         except KeyError:
diff --git a/rpython/annotator/description.py b/rpython/annotator/description.py
--- a/rpython/annotator/description.py
+++ b/rpython/annotator/description.py
@@ -489,10 +489,7 @@
             if name in cls.__dict__:
                 return  # ignore misbehaving descriptors and the like
             raise
-        try:
-            value = normalize_method(value)
-        except ValueError:
-            pass
+        value = normalize_method(value)
         if isinstance(value, InstanceMethod):
             func = value.im_func
             if isinstance(func, types.FunctionType):
diff --git a/rpython/rtyper/extregistry.py b/rpython/rtyper/extregistry.py
--- a/rpython/rtyper/extregistry.py
+++ b/rpython/rtyper/extregistry.py
@@ -22,10 +22,7 @@
         else:
             if key in dict:
                 raise ValueError("duplicate extregistry entry %r" % (selfcls,))
-            try:
-                key = normalize_method(key)
-            except ValueError:
-                pass
+            key = normalize_method(key)
             dict[key] = selfcls
 
     def _register_value(selfcls, key):
@@ -131,10 +128,7 @@
         return _lookup_type_cls(type(instance))
 
 def lookup(instance):
-    try:
-        instance = normalize_method(instance)
-    except ValueError:
-        pass
+    instance = normalize_method(instance)
     Entry = _lookup_cls(instance)
     return Entry(type(instance), instance)
 
diff --git a/rpython/tool/descriptor.py b/rpython/tool/descriptor.py
--- a/rpython/tool/descriptor.py
+++ b/rpython/tool/descriptor.py
@@ -40,7 +40,7 @@
         if isinstance(method, types.MethodType):
             return InstanceMethod(method.__func__, method.__self__, method.im_class)
         else:
-            raise ValueError('Not a method')
+            return method
 
 else:
     slot_wrapper = type(object.__init__)
@@ -66,6 +66,6 @@
         elif isinstance(method, method_descriptor):
             cls = method.__objclass__
             return InstanceMethod(method, None, method.__objclass__)
-        raise ValueError('Not a method')
+        return method
 
 


More information about the pypy-commit mailing list