Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix a bug that caused incorrect parsing of assertion expressions cont…

…aining

lists.
  • Loading branch information...
commit e651670e56a7080ca7e24ce720cb3cbab07655ff 1 parent b187143
Aldo Cortesi authored July 05, 2008
6  libpry/explain.py
@@ -21,7 +21,7 @@ def __init__(self, s):
21 21
     def show(self, glob, loc):
22 22
         try:
23 23
             return repr(eval(self.s, glob, loc))
24  
-        except SyntaxError:
  24
+        except SyntaxError, v:
25 25
             return "<could not be evaluated>"
26 26
 
27 27
     def __eq__(self, other):
@@ -54,9 +54,9 @@ def parseExpression(self, expr):
54 54
             for i in list(tokenize.generate_tokens(_Wrap(expr))):
55 55
                 name, txt = tokenize.tok_name[i[0]], i[1]
56 56
                 start, end = i[2][1], i[3][1]
57  
-                if name == "OP" and txt == "(":
  57
+                if name == "OP" and (txt == "(" or txt == "["):
58 58
                     nest += 1
59  
-                elif name == "OP" and txt == ")":
  59
+                elif name == "OP" and (txt == ")" or txt == "]"):
60 60
                     nest -= 1
61 61
                 elif nest == 0:
62 62
                     if name == "OP" and txt in self._specialOps:
7  test/test_explain.py
@@ -82,6 +82,13 @@ def test_unbalanced(self):
82 82
         assert not self.s.parseExpression("[a == b and c == d, foo")[0]
83 83
         assert not self.s.parseExpression("a == b and c == d, foo]")[0]
84 84
 
  85
+    def test_list(self):
  86
+        r, s = self.s.parseExpression('[0, 2]')
  87
+        expected = [
  88
+            explain.Expression('[0, 2]'),
  89
+        ]
  90
+        assert r == expected
  91
+
85 92
     def test_str(self):
86 93
         r = explain.Explain(
87 94
                 "a == b and c == d, foo",

0 notes on commit e651670

Please sign in to comment.
Something went wrong with that request. Please try again.