[Python-checkins] r53883 - sandbox/trunk/pep362/pep362.py sandbox/trunk/pep362/test_pep362.py

brett.cannon python-checkins at python.org
Sat Feb 24 16:28:06 CET 2007


Author: brett.cannon
Date: Sat Feb 24 16:28:06 2007
New Revision: 53883

Modified:
   sandbox/trunk/pep362/pep362.py
   sandbox/trunk/pep362/test_pep362.py
Log:
Turn on Signature.bind tests and add a (failing) one for keyword-only arguments
in Py3K.


Modified: sandbox/trunk/pep362/pep362.py
==============================================================================
--- sandbox/trunk/pep362/pep362.py	(original)
+++ sandbox/trunk/pep362/pep362.py	Sat Feb 24 16:28:06 2007
@@ -207,7 +207,9 @@
         are present is to posssibly mutate an iterator then the method gives up
         and raises a BindError.  This is to prevent something like a generator
         which is about to be used for an actual function call from being
-        exhausted by this method."""
+        exhausted by this method.
+        
+        """
         bindings = {}
         arg_names_seq = [param.name for param in self.parameters]
         arg_names_set = set(arg_names_seq)
@@ -225,7 +227,7 @@
             self.__positional_bind(arg_name, value, bindings)
         # Keyword arguments.
         var_kw_args = {}
-        for key, value in kwargs.items():
+        for key, value in list(kwargs.items()):
             if key not in arg_names_set:
                 if not self.var_kw_args:
                     raise TypeError("unexpected keyword argument: %r" % key)
@@ -250,7 +252,7 @@
                     bindings[param.name] = param.default_value
 
         # Make sure all required arguments are bound to.
-        for bound in bindings.iterkeys():
+        for bound in bindings.keys():
             try:
                 required_args.remove(bound)
             except KeyError:

Modified: sandbox/trunk/pep362/test_pep362.py
==============================================================================
--- sandbox/trunk/pep362/test_pep362.py	(original)
+++ sandbox/trunk/pep362/test_pep362.py	Sat Feb 24 16:28:06 2007
@@ -282,6 +282,13 @@
                 ('e', ('f',)):(4, (5,)), 'g':(6,), 'h':{'i':7}}
         self.failUnlessEqual(expected, binding)
 
+    @py3k_test
+    def test_keyword_only(self):
+        sig = pep362.Signature(pep362_py3k_fodder.keyword_only)
+        binding = sig.bind(a=42)
+        self.failUnlessEqual(binding, {'a':42})
+        self.failUnlessRaises(pep362.BindError, sig.bind, 42)
+
     def test_BindError(self):
         def gen():
             yield 0
@@ -293,6 +300,7 @@
 def test_main():
     test_support.run_unittest(ParameterObjectTests,
                                 SignatureObjectTests,
+                                SignatureBindTests,
                              )
 
 


More information about the Python-checkins mailing list