Skip to content

bpo-30529: Fix assert failure in with pydebug; add tests.#2232

Merged
serhiy-storchaka merged 2 commits into
python:masterfrom
ericvsmith:bpo-30529-assert
Jun 16, 2017
Merged

bpo-30529: Fix assert failure in with pydebug; add tests.#2232
serhiy-storchaka merged 2 commits into
python:masterfrom
ericvsmith:bpo-30529-assert

Conversation

@ericvsmith

Copy link
Copy Markdown
Member

This removes an assert that fails, and adds tests.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few nitpicks.

And needed a Misc/NEWS entry.

Comment thread Python/ast.c Outdated
NULL). */
} else if (!state->last_str) {
/* Note that the literal can be zero length, if the
Input string is "\\\n" or "\\\r". */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or "\\\r\n".

The word "Input" shouldn't start from a capital letter.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it.

Comment thread Lib/test/test_fstring.py Outdated
# As part of bpo-30529, this used to raise an assert in pydebug mode.
for i in range(1, 32):
with self.subTest(i=i):
# This will result in a backslash followed by the control

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A backslash followed by the control character (except '\r' and '\n') produces a DeprecationWarning.

I would test just a case of '\\\n'. Maybe also '\\\r' and '\\\r\n' if you prefer.

@ericvsmith ericvsmith Jun 16, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I think I'll just test '\\\r' and '\\\n'.

Comment thread Lib/test/test_fstring.py Outdated
# string. The same thing happens with non-fstrings.
expected_len = 0 if i in (10, 13) else 2
s = f'f"\\{chr(i)}"'
self.assertEqual(len(eval(s)), expected_len)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can test not just length, but a value. This could produce more informative error message if the eval() returns unexpected result.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just test the zero length versions.

@serhiy-storchaka

Copy link
Copy Markdown
Member

Since 3.6.0 is affected, bpo-30529 is not related.

@ericvsmith ericvsmith left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed on this not being related to bpo-30529. I'll create a new issue.

Comment thread Lib/test/test_fstring.py Outdated
# As part of bpo-30529, this used to raise an assert in pydebug mode.
for i in range(1, 32):
with self.subTest(i=i):
# This will result in a backslash followed by the control

@ericvsmith ericvsmith Jun 16, 2017

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. I think I'll just test '\\\r' and '\\\n'.

Comment thread Lib/test/test_fstring.py Outdated
# string. The same thing happens with non-fstrings.
expected_len = 0 if i in (10, 13) else 2
s = f'f"\\{chr(i)}"'
self.assertEqual(len(eval(s)), expected_len)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just test the zero length versions.

Comment thread Python/ast.c Outdated
NULL). */
} else if (!state->last_str) {
/* Note that the literal can be zero length, if the
Input string is "\\\n" or "\\\r". */

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix it.

@ericvsmith

Copy link
Copy Markdown
Member Author

I've created bpo-30682 and updated my commit to reflect Serhiy's comments.

@serhiy-storchaka serhiy-storchaka merged commit 11e97f2 into python:master Jun 16, 2017
serhiy-storchaka pushed a commit to serhiy-storchaka/cpython that referenced this pull request Jun 16, 2017
…in f-strings. (pythonGH-2232)

This caused a segfault on eval("f'\\\n'") and eval("f'\\\r'") in debug build..
(cherry picked from commit 11e97f2)
ericvsmith pushed a commit that referenced this pull request Jun 16, 2017
…in f-strings. (GH-2232) (#2242)

This caused a segfault on eval("f'\\\n'") and eval("f'\\\r'") in debug build..
(cherry picked from commit 11e97f2)
@ericvsmith ericvsmith deleted the bpo-30529-assert branch January 6, 2018 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants