[pypy-commit] pypy py3k: add a couple of annotation time type checks

antocuni noreply at buildbot.pypy.org
Fri Aug 17 21:59:45 CEST 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r56741:513f218a7d2d
Date: 2012-08-17 17:54 +0200
http://bitbucket.org/pypy/pypy/changeset/513f218a7d2d/

Log:	add a couple of annotation time type checks

diff --git a/pypy/interpreter/argument.py b/pypy/interpreter/argument.py
--- a/pypy/interpreter/argument.py
+++ b/pypy/interpreter/argument.py
@@ -6,7 +6,6 @@
 from pypy.rlib.debug import make_sure_not_resized
 from pypy.rlib import jit
 
-
 class Signature(object):
     _immutable_ = True
     _immutable_fields_ = ["argnames[*]", "kwonlyargnames[*]"]
@@ -92,6 +91,16 @@
         raise IndexError
 
 
+def assert_list_of_unicode(value):
+    from pypy.rlib.debug import check_annotation
+    def checker(ann, bk):
+        from pypy.annotation.model import SomeList, SomeUnicodeString
+        if not isinstance(ann, SomeList):
+            raise TypeError
+        if not isinstance(ann.listdef.listitem.s_value, SomeUnicodeString):
+            raise TypeError
+    check_annotation(value, checker)
+
 
 class Arguments(object):
     """
@@ -105,12 +114,13 @@
     """
 
     ###  Construction  ###
-
     def __init__(self, space, args_w, keywords=None, keywords_w=None,
                  w_stararg=None, w_starstararg=None, keyword_names_w=None):
         self.space = space
         assert isinstance(args_w, list)
         self.arguments_w = args_w
+        assert_list_of_unicode(keywords)
+        
         self.keywords = keywords
         self.keywords_w = keywords_w
         self.keyword_names_w = keyword_names_w  # matches the tail of .keywords
@@ -187,6 +197,7 @@
         # unpack the ** arguments
         space = self.space
         keywords, values_w = space.view_as_kwargs(w_starstararg)
+        assert_list_of_unicode(keywords)
         if keywords is not None: # this path also taken for empty dicts
             if self.keywords is None:
                 self.keywords = keywords[:] # copy to make non-resizable


More information about the pypy-commit mailing list