Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r89533:ec2d5317659d
Date: 2017-01-12 23:13 +0100
http://bitbucket.org/pypy/pypy/changeset/ec2d5317659d/

Log:    Test and fix for an issue with braces inside brackets

diff --git a/pypy/objspace/std/newformat.py b/pypy/objspace/std/newformat.py
--- a/pypy/objspace/std/newformat.py
+++ b/pypy/objspace/std/newformat.py
@@ -122,6 +122,11 @@
                             nested -= 1
                             if not nested:
                                 break
+                        elif c == "[":
+                            i += 1
+                            while i < end and s[i] != "]":
+                                i += 1
+                            continue
                         i += 1
                     if nested:
                         raise oefmt(space.w_ValueError, "Unmatched '{'")
@@ -214,7 +219,10 @@
                 try:
                     w_arg = self.args[index]
                 except IndexError:
-                    raise oefmt(space.w_IndexError, "out of range")
+                    raise oefmt(space.w_IndexError,
+                                "out of range: index %d but only %d 
argument%s",
+                                index, len(self.args),
+                                "s" if len(self.args) != 1 else "")
             return self._resolve_lookups(w_arg, name, i, end)
 
         @jit.unroll_safe
diff --git a/pypy/objspace/std/test/test_newformat.py 
b/pypy/objspace/std/test/test_newformat.py
--- a/pypy/objspace/std/test/test_newformat.py
+++ b/pypy/objspace/std/test/test_newformat.py
@@ -191,6 +191,11 @@
         assert self.s('{0:\x00<12}').format(3+2.0j) == '(3+2j)' + '\x00' * 6
         assert self.s('{0:\x01<12}').format(3+2.0j) == '(3+2j)' + '\x01' * 6
 
+    def test_more_indexing_cases(self):
+        assert self.s('x{[3]}y').format(['a', 'b', 'c', 'd', 'e']) == 'xdy'
+        assert self.s('x{[[]}y').format({'[': 'a'}) == 'xay'
+        assert self.s('x{[{]}y').format({'{': 'a'}) == 'xay'
+
 
 class AppTestUnicodeFormat(BaseStringFormatTests):
     def setup_class(cls):
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to