Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

…aining

lists.
  • Loading branch information...
commit e651670e56a7080ca7e24ce720cb3cbab07655ff 1 parent b187143
@cortesi authored
Showing with 10 additions and 3 deletions.
  1. +3 −3 libpry/explain.py
  2. +7 −0 test/test_explain.py
View
6 libpry/explain.py
@@ -21,7 +21,7 @@ def __init__(self, s):
def show(self, glob, loc):
try:
return repr(eval(self.s, glob, loc))
- except SyntaxError:
+ except SyntaxError, v:
return "<could not be evaluated>"
def __eq__(self, other):
@@ -54,9 +54,9 @@ def parseExpression(self, expr):
for i in list(tokenize.generate_tokens(_Wrap(expr))):
name, txt = tokenize.tok_name[i[0]], i[1]
start, end = i[2][1], i[3][1]
- if name == "OP" and txt == "(":
+ if name == "OP" and (txt == "(" or txt == "["):
nest += 1
- elif name == "OP" and txt == ")":
+ elif name == "OP" and (txt == ")" or txt == "]"):
nest -= 1
elif nest == 0:
if name == "OP" and txt in self._specialOps:
View
7 test/test_explain.py
@@ -82,6 +82,13 @@ def test_unbalanced(self):
assert not self.s.parseExpression("[a == b and c == d, foo")[0]
assert not self.s.parseExpression("a == b and c == d, foo]")[0]
+ def test_list(self):
+ r, s = self.s.parseExpression('[0, 2]')
+ expected = [
+ explain.Expression('[0, 2]'),
+ ]
+ assert r == expected
+
def test_str(self):
r = explain.Explain(
"a == b and c == d, foo",
Please sign in to comment.
Something went wrong with that request. Please try again.