Brent Westbrook
38c074e67d
Catch syntax errors in nested interpolations before Python 3.12 ( #20949 )
...
Summary
--
This PR fixes the issue I added in #20867 and noticed in #20930 . Cases
like this
cause an error on any Python version:
```py
f"{1:""}"
```
which gave me a false sense of security before. Cases like this are
still
invalid only before 3.12 and weren't flagged after the changes in
#20867 :
```py
f'{1: abcd "{'aa'}" }'
# ^ reused quote
f'{1: abcd "{"\n"}" }'
# ^ backslash
```
I didn't recognize these as nested interpolations that also need to be
checked
for invalid expressions, so filtering out the whole format spec wasn't
quite
right. And `elements.interpolations()` only iterates over the outermost
interpolations, not the nested ones.
There's basically no code change in this PR, I just moved the existing
check
from `parse_interpolated_string`, which parses the entire string, to
`parse_interpolated_element`. This kind of seems more natural anyway and
avoids
having to try to recursively visit nested elements after the fact in
`parse_interpolated_string`. So viewing the diff with something like
```
git diff --color-moved --ignore-space-change --color-moved-ws=allow-indentation-change main
```
should make this more clear.
Test Plan
--
New tests
2025-10-20 09:03:13 -04:00
..
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-05-07 14:11:35 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-30 15:04:00 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-30 15:04:00 -04:00
2024-06-03 18:23:50 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-19 16:46:15 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-05 13:19:09 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-06-17 06:47:00 +00:00
2024-06-17 06:47:00 +00:00
2024-06-17 06:47:00 +00:00
2024-06-17 06:47:00 +00:00
2024-04-18 17:57:39 +05:30
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-29 12:07:20 -04:00
2025-03-17 11:17:27 +00:00
2025-03-17 11:17:27 +00:00
2025-03-05 17:08:18 +00:00
2025-03-17 11:17:27 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-05 17:08:18 +00:00
2025-03-17 11:17:27 +00:00
2024-04-18 17:57:39 +05:30
2025-03-29 12:07:20 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-10-17 21:35:48 +00:00
2024-04-18 17:57:39 +05:30
2025-04-03 17:55:37 -04:00
2025-04-03 17:55:37 -04:00
2025-03-21 15:06:22 -04:00
2025-03-04 16:50:09 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-29 07:55:30 -05:00
2025-04-29 07:55:30 -05:00
2025-06-16 11:44:42 -05:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-13 15:55:17 -04:00
2024-04-18 17:57:39 +05:30
2024-04-23 04:19:05 +00:00
2024-04-23 04:19:05 +00:00
2024-04-23 04:19:05 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-05 13:19:09 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-09-16 15:53:28 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-08 08:55:43 -04:00
2025-04-08 08:55:43 -04:00
2025-04-08 08:55:43 -04:00
2025-04-08 08:56:25 -04:00
2025-04-08 08:55:43 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-09-25 13:52:24 -04:00
2024-04-18 17:57:39 +05:30
2025-03-26 12:27:16 -04:00
2025-03-06 11:57:20 -05:00
2025-03-06 11:57:20 -05:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-02-27 10:23:15 -05:00
2024-06-03 18:23:50 +05:30
2024-06-03 18:23:50 +05:30
2024-06-03 18:23:50 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-06-03 18:23:50 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-03 17:32:39 -04:00
2024-04-18 17:57:39 +05:30
2025-09-24 19:32:55 +00:00
2025-03-14 15:06:42 -04:00
2025-03-14 15:06:42 -04:00
2025-04-08 12:50:52 -04:00
2025-10-15 09:23:16 -04:00
2024-04-19 11:36:26 +00:00
2025-04-24 16:11:46 -04:00
2025-04-24 16:11:46 -04:00
2025-04-24 16:11:46 -04:00
2025-04-24 16:11:46 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-14 15:20:44 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-17 08:54:55 -04:00
2025-03-06 12:18:13 -05:00
2025-03-18 11:12:15 -04:00
2025-10-20 09:03:13 -04:00
2025-03-05 13:46:43 +00:00
2024-12-19 13:36:32 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-21 14:45:25 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-04-02 08:38:25 -04:00
2025-04-02 08:38:25 -04:00
2025-04-02 08:38:25 -04:00
2025-03-29 12:35:47 -04:00
2025-03-14 14:51:34 +00:00
2025-03-14 14:51:34 +00:00
2025-05-30 15:00:56 -05:00
2025-05-30 15:00:56 -05:00
2025-05-30 15:00:56 -05:00
2025-05-30 15:00:56 -05:00
2025-05-30 15:00:56 -05:00
2025-05-30 15:00:56 -05:00
2025-05-30 15:00:56 -05:00
2025-07-27 12:41:03 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-12-10 17:50:55 -06:00
2025-10-13 14:13:27 -04:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2025-03-04 16:53:38 +00:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-26 09:47:29 +02:00
2024-04-26 09:47:29 +02:00
2024-04-26 09:47:29 +02:00
2024-04-26 09:47:29 +02:00
2024-04-18 17:57:39 +05:30
2024-04-26 09:47:29 +02:00
2024-04-26 09:47:29 +02:00
2024-06-26 08:10:35 +05:30
2025-03-04 17:20:10 +00:00
2025-03-14 15:06:42 -04:00
2025-03-14 15:06:42 -04:00
2025-03-14 15:06:42 -04:00
2024-04-18 17:57:39 +05:30
2025-02-28 17:13:46 -05:00
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-04-18 17:57:39 +05:30
2024-06-06 08:59:56 +00:00
2024-04-18 17:57:39 +05:30
2025-03-29 12:07:20 -04:00
2025-09-03 10:13:05 -04:00