[3.6] bpo-30682: Removed a too-strict assertion that failed for certa… · python/cpython@2eca5b4 (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -780,5 +780,11 @@ def test_dict(self): | ||
780 | 780 | self.assertEqual(f'{d["foo"]}', 'bar') |
781 | 781 | self.assertEqual(f"{d['foo']}", 'bar') |
782 | 782 | |
783 | +def test_backslash_char(self): | |
784 | +# Check eval of a backslash followed by a control char. | |
785 | +# See bpo-30682: this used to raise an assert in pydebug mode. | |
786 | +self.assertEqual(eval('f"\\\n"'), '') | |
787 | +self.assertEqual(eval('f"\\\r"'), '') | |
788 | + | |
783 | 789 | if __name__ == '__main__': |
784 | 790 | unittest.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -10,6 +10,9 @@ What's New in Python 3.6.2 release candidate 1? | ||
10 | 10 | Core and Builtins |
11 | 11 | ----------------- |
12 | 12 | |
13 | +- bpo-30682: Removed a too-strict assertion that failed for certain f-strings, | |
14 | + such as eval("f'\\\n'") and eval("f'\\\r'"). | |
15 | + | |
13 | 16 | - bpo-30604: Move co_extra_freefuncs to not be per-thread to avoid crashes |
14 | 17 | |
15 | 18 | - bpo-29104: Fixed parsing backslashes in f-strings. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -4887,6 +4887,8 @@ FstringParser_ConcatFstring(FstringParser *state, const char **str, | ||
4887 | 4887 | /* Do nothing. Just leave last_str alone (and possibly |
4888 | 4888 | NULL). */ |
4889 | 4889 | } else if (!state->last_str) { |
4890 | +/* Note that the literal can be zero length, if the | |
4891 | + input string is "\\\n" or "\\\r", among others. */ | |
4890 | 4892 | state->last_str = literal; |
4891 | 4893 | literal = NULL; |
4892 | 4894 | } else { |
@@ -4896,8 +4898,6 @@ FstringParser_ConcatFstring(FstringParser *state, const char **str, | ||
4896 | 4898 | return -1; |
4897 | 4899 | literal = NULL; |
4898 | 4900 | } |
4899 | -assert(!state->last_str | | |
4900 | -PyUnicode_GET_LENGTH(state->last_str) != 0); | |
4901 | 4901 | |
4902 | 4902 | /* We've dealt with the literal now. It can't be leaked on further |
4903 | 4903 | errors. */ |