-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Remove newlines from left/right operands with '-vv' #9743
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
Conversation
for more information, see https://pre-commit.ci
Thanks @samuelcolvin - this looks good to me, though I'll leave merging to another maintainer to be sure 🙂 |
Here's the output of
And here's the output of this PR:
So clearly an improvement! 👍 |
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.
Thanks @samuelcolvin, appreciate a lot the PR! Very clean work. 👍
@@ -160,8 +160,8 @@ def assertrepr_compare(config, op: str, left: Any, right: Any) -> Optional[List[ | |||
"""Return specialised explanations for some operators/operands.""" | |||
verbose = config.getoption("verbose") | |||
if verbose > 1: | |||
left_repr = safeformat(left) | |||
right_repr = safeformat(right) | |||
left_repr = saferepr_unlimited(left) |
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.
Indeed using safeformat
for the left and right operands when verbose > 1
is not what is expected, because safeformat
introduces newlines, and the result of assertrepr_compare
is expected to be a list of lines; the string produced by safeformat
(containing \n
) is put as a single string in the result, which causes them to be escaped by the terminal later (I assume).
So the fix is entirely correct: use repr
to produce the representation without \n
, which is used to build the summary
variable which is expected to be a single line.
AssertionError
message
fix #9742
I've done this in the least intrusive way possible, a cleaner solution would be to alter
saferepr
to behave like the newsaferepr_unlimited
method whenmaxsize=None
, but that might effect some other code (though I think use ofsaferepr()
withmaxsize=None
is very rare).