8000 [3.6] bpo-30682: Removed a too-strict assertion that failed for certain f-strings. (GH-2232) by serhiy-storchaka · Pull Request #2242 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.6] bpo-30682: Removed a too-strict assertion that failed for certain f-strings. (GH-2232) #2242

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

Merged
merged 1 commit into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/test/test_fstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,5 +780,11 @@ def test_dict(self):
self.assertEqual(f'{d["foo"]}', 'bar')
self.assertEqual(f"{d['foo']}", 'bar')

def test_backslash_char(self):
# Check eval of a backslash followed by a control char.
# See bpo-30682: this used to raise an assert in pydebug mode.
self.assertEqual(eval('f"\\\n"'), '')
self.assertEqual(eval('f"\\\r"'), '')

if __name__ == '__main__':
unittest.main()
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ What's New in Python 3.6.2 release candidate 1?
Core and Builtins
-----------------

- bpo-30682: Removed a too-strict assertion that failed for certain f-strings,
such as eval("f'\\\n'") and eval("f'\\\r'").

- bpo-30604: Move co_extra_freefuncs to not be per-thread to avoid crashes

- bpo-29104: Fixed parsing backslashes in f-strings.
Expand Down
4 changes: 2 additions & 2 deletions Python/ast.c
603A
Original file line number Diff line number Diff line change
Expand Up @@ -4887,6 +4887,8 @@ FstringParser_ConcatFstring(FstringParser *state, const char **str,
/* Do nothing. Just leave last_str alone (and possibly
NULL). */
} else if (!state->last_str) {
/* Note that the literal can be zero length, if the
input string is "\\\n" or "\\\r", among others. */
state->last_str = literal;
literal = NULL;
} else {
Expand All @@ -4896,8 +4898,6 @@ FstringParser_ConcatFstring(FstringParser *state, const char **str,
return -1;
literal = NULL;
}
assert(!state->last_str ||
PyUnicode_GET_LENGTH(state->last_str) != 0);

/* We've dealt with the literal now. It can't be leaked on further
errors. */
Expand Down
0