-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve of the test output for logical expression with brackets. #1669
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""Rewrite assertion AST to produce nice error messages""" | ||
|
||
import ast | ||
import _ast | ||
import errno | ||
import itertools | ||
import imp | ||
|
@@ -753,6 +754,8 @@ def visit_BoolOp(self, boolop): | |
self.statements = save | ||
self.on_failure = fail_save | ||
expl_template = self.helper("format_boolop", expl_list, ast.Num(is_or)) | ||
#if isinstance(boolop, (_ast.Compare, _ast.BoolOp)): | ||
# expl_template = "({0})".format(expl_template) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will change it the next days. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
expl = self.pop_format_context(expl_template) | ||
return ast.Name(res_var, ast.Load()), self.explanation_param(expl) | ||
|
||
|
@@ -855,6 +858,8 @@ def visit_Attribute(self, attr): | |
def visit_Compare(self, comp): | ||
self.push_format_context() | ||
left_res, left_expl = self.visit(comp.left) | ||
if isinstance(comp.left, (_ast.Compare, _ast.BoolOp)): | ||
left_expl = "({0})".format(left_expl) | ||
res_variables = [self.variable() for i in range(len(comp.ops))] | ||
load_names = [ast.Name(v, ast.Load()) for v in res_variables] | ||
store_names = [ast.Name(v, ast.Store()) for v in res_variables] | ||
|
@@ -864,6 +869,8 @@ def visit_Compare(self, comp): | |
results = [left_res] | ||
for i, op, next_operand in it: | ||
next_res, next_expl = self.visit(next_operand) | ||
if isinstance(next_operand, (_ast.Compare, _ast.BoolOp)): | ||
next_expl = "({0})".format(next_expl) | ||
results.append(next_res) | ||
sym = binop_map[op.__class__] | ||
syms.append(ast.Str(sym)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those conflict markers don't belong here 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed