Skip to content

Commit

Permalink
fix the regex some more
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharsadhwani committed Aug 1, 2024
1 parent b3f17f4 commit b5d954d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/blib2to3/pgen2/tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ def _combinations(*l: str) -> Set[str]:
)

# beginning of a single quoted f-string. must not end with `{{` or `\N{`
SingleLbrace = r"(?:\\N{|\\[^{]|{{|[^\n'\\{])*(?<!\\N)({)(?!{)"
DoubleLbrace = r'(?:\\N{|\\[^{]|{{|[^\n"\\{])*(?<!\\N)({)(?!{)'
SingleLbrace = r"(?:\\N{|{{|\\'|[^\n'{])*(?<!\\N)({)(?!{)"
DoubleLbrace = r'(?:\\N{|{{|\\"|[^\n"{])*(?<!\\N)({)(?!{)'

# beginning of a triple quoted f-string. must not end with `{{` or `\N{`
Single3Lbrace = r"(?:\\N{|\\[^{]|{{|'(?!'')|[^'{\\])*(?<!\\N){(?!{)"
Double3Lbrace = r'(?:\\N{|\\[^{]|{{|"(?!"")|[^"{\\])*(?<!\\N){(?!{)'
Single3Lbrace = r"(?:\\N{|{{|\\'|'(?!'')|[^'{])*(?<!\\N){(?!{)"
Double3Lbrace = r'(?:\\N{|{{|\\"|"(?!"")|[^"{])*(?<!\\N){(?!{)'

# ! format specifier inside an fstring brace, ensure it's not a `!=` token
Bang = Whitespace + group("!") + r"(?!=)"
Expand Down
4 changes: 4 additions & 0 deletions tests/data/cases/pep_701.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@

f'{1}\{{'
f'{2} foo \{{[\}}'
f'\{3}'
rf"\{"a"}"

# output

Expand Down Expand Up @@ -270,3 +272,5 @@

f"{1}\{{"
f"{2} foo \{{[\}}"
f"\{3}"
rf"\{"a"}"

0 comments on commit b5d954d

Please sign in to comment.