You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Python] Fixes for string escapes, placeholders, replacements (sublimehq#4366)
* [Python] Scope placeholders in raw strings
This commit includes `string-placeholders` context to raw strings
as all of them can be used as format-strings in e.g. `R"Hello %s" % R'World'`.
* [Python] Reorder context includes
This commit reorders include statements to reduce syntax cache size.
* [Python] Fix string replacements
This commit...
1. moves string-replacement includes before includes of normal escapes
to make sure special `{{` and `\{{` escape patterns take precedence.
2. removes string-replacement includes from b-strings as those don't
support format methods such as `b"{0}".format(b"invalid")` and string
format placeholders are not scoped as well.
3. adds string-replacement includes to plain raw strings, as those can be
used in format strings and string format placeholders have been added,
before.
Notes:
- raw SQL strings already include them
- raw RegExp strings need more work to prevent ambiguities with braced
quantifiers such as `{1}`, hence don't include them at the moment.
* [Python] Drop unicode escapes from raw-strings
This commit removes `escaped-unicode-chars` context includes from all raw
string content contexts as each of them returns e.g. `\u2020` unchanged.
* [Python] Merge escaped string replacement braces
As a result of reordering string-replacement contexts, it turns out f-strings
and normal string-replacements sharing same brace escaping rules.
* [Python] Move and extend some f-string tests
This commit...
1. moves various tests to group f-string tests.
2. adds tests for escape sequences and placeholders in all sorts of f-strings.
* [Python] Add tests to verify recent changes
This commit adds tests for all sorts of (except f-) strings to verify escape
sequences, placeholders and string replacements being applied as expected.
* [Python] Restrict known regexp escape sequences
This commit overrides `known_char_escape` variable in python's regexp syntax to
1. scope all `\c` sequences illegal, even when followed by numbers,
as python's `re` and `regex` modules don't support it.
2. remove explicit patterns `\\[tnrfae]` as those are handled by default
escape pattern `\.`.
0 commit comments