Commit fcaa8bf
Friday
Fix spurious E231 for nested f-string format specifiers
When a replacement field appears inside an f-string format spec
(e.g. `f"{x:0.{digits:d}f}"`), the `:` in the nested `{digits:d}` is a
format specifier, not a dict colon. Previously pycodestyle reported a
false-positive E231 on it because the brace-stack pattern `['f', '{']`
only matched the top-level replacement field.
Track `FSTRING_MIDDLE` / `TSTRING_MIDDLE` tokens: when `{` is opened
immediately after one of these tokens it is a nested replacement field
inside a format spec. Push `'F'` (instead of `'{'`) onto the brace
stack, then suppress E231 for `:` when the top of the stack is `'F'`.
Fixes #1241.1 parent 8b53059 commit fcaa8bf
2 files changed
+27
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
874 | 874 | | |
875 | 875 | | |
876 | 876 | | |
| 877 | + | |
877 | 878 | | |
878 | 879 | | |
879 | | - | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
880 | 888 | | |
881 | 889 | | |
882 | 890 | | |
| |||
897 | 905 | | |
898 | 906 | | |
899 | 907 | | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
900 | 918 | | |
901 | 919 | | |
902 | 920 | | |
| |||
912 | 930 | | |
913 | 931 | | |
914 | 932 | | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
915 | 936 | | |
916 | 937 | | |
917 | 938 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
0 commit comments