Author: Ronan Lamy <ronan.l...@gmail.com>
Branch: 
Changeset: r94048:e4136ea7f1b6
Date: 2018-03-21 10:25 +0000
http://bitbucket.org/pypy/pypy/changeset/e4136ea7f1b6/

Log:    Merged in rpython-sprint (pull request #598)

        Cleanup + document enforceargs()

diff --git a/rpython/annotator/signature.py b/rpython/annotator/signature.py
--- a/rpython/annotator/signature.py
+++ b/rpython/annotator/signature.py
@@ -103,7 +103,7 @@
     elif bookkeeper and not hasattr(t, '_freeze_'):
         return SomeInstance(bookkeeper.getuniqueclassdef(t))
     else:
-        raise AssertionError("annotationoftype(%r)" % (t,))
+        raise TypeError("Annotation of type %r not supported" % (t,))
 
 class Sig(object):
 
diff --git a/rpython/doc/rpython.rst b/rpython/doc/rpython.rst
--- a/rpython/doc/rpython.rst
+++ b/rpython/doc/rpython.rst
@@ -259,6 +259,26 @@
   intmask().
 
 
+Type Enforcing and Checking
+---------------------------
+
+RPython provides a helper decorator to force RPython-level types on function
+arguments. The decorator, called ``enforceargs()``, accepts as parameters the
+types expected to match the arguments of the function.
+
+Functions decorated with ``enforceargs()`` have their function signature
+analyzed and their RPython-level type inferred at import time (for further
+details about the flavor of translation performed in RPython, see the
+`Annotation pass documentation`_). Encountering types not supported by RPython
+will raise a ``TypeError``.
+
+``enforceargs()`` by default also performs type checking of parameter types
+each time the function is invoked. To disable this behavior, it's possible to
+pass the ``typecheck=False`` parameter to the decorator.
+
+.. _Annotation pass documentation: 
http://rpython.readthedocs.io/en/latest/translation.html#annotator
+
+
 Exception rules
 ---------------
 
diff --git a/rpython/doc/translation.rst b/rpython/doc/translation.rst
--- a/rpython/doc/translation.rst
+++ b/rpython/doc/translation.rst
@@ -48,7 +48,7 @@
    be present in memory as a form that is "static enough" in the sense of
    :doc:`RPython <rpython>`.
 
-2. The Annotator_ performs a global analysis starting from an specified
+2. The Annotator_ performs a global analysis starting from a specified
    entry point to deduce type and other information about what each
    variable can contain at run-time, :ref:`building flow graphs <flow-graphs>`
    as it encounters them.
diff --git a/rpython/rlib/objectmodel.py b/rpython/rlib/objectmodel.py
--- a/rpython/rlib/objectmodel.py
+++ b/rpython/rlib/objectmodel.py
@@ -120,7 +120,7 @@
     """ Decorate a function with forcing of RPython-level types on arguments.
     None means no enforcing.
 
-    When not translated, the type of the actual arguments are checked against
+    When not translated, the type of the actual arguments is checked against
     the enforced types every time the function is called. You can disable the
     typechecking by passing ``typecheck=False`` to @enforceargs.
     """
@@ -147,8 +147,7 @@
             # they are already homogeneous, so we only check the first
             # item. The case of empty list/dict is handled inside typecheck()
             if isinstance(arg, list):
-                item = arg[0]
-                return [get_type_descr_of_argument(item)]
+                return [get_type_descr_of_argument(arg[0])]
             elif isinstance(arg, dict):
                 key, value = next(arg.iteritems())
                 return {get_type_descr_of_argument(key): 
get_type_descr_of_argument(value)}
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to