From aa12347a1997d2acdf7a1973af7b5dbce54b9bd0 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Mon, 21 Oct 2024 20:19:17 -0400 Subject: [PATCH] fix named escapes in FSTRING_MIDDLE --- pyupgrade/_string_helpers.py | 14 ++------------ setup.cfg | 2 +- tests/main_test.py | 2 ++ 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/pyupgrade/_string_helpers.py b/pyupgrade/_string_helpers.py index edea309c..7855e970 100644 --- a/pyupgrade/_string_helpers.py +++ b/pyupgrade/_string_helpers.py @@ -1,11 +1,11 @@ from __future__ import annotations import codecs -import re import string from typing import Optional -NAMED_UNICODE_RE = re.compile(r'(? str: return ''.join(_convert_tup(tup) for tup in parsed) -def curly_escape(s: str) -> str: - parts = NAMED_UNICODE_RE.split(s) - return ''.join( - part.replace('{', '{{').replace('}', '}}') - if not NAMED_UNICODE_RE.fullmatch(part) - else part - for part in parts - ) - - def is_codec(encoding: str, name: str) -> bool: try: return codecs.lookup(encoding).name == name diff --git a/setup.cfg b/setup.cfg index 05ada332..320b3778 100644 --- a/setup.cfg +++ b/setup.cfg @@ -19,7 +19,7 @@ classifiers = [options] packages = find: install_requires = - tokenize-rt>=5.2.0 + tokenize-rt>=6.1.0 python_requires = >=3.9 [options.packages.find] diff --git a/tests/main_test.py b/tests/main_test.py index a254573a..bf595db3 100644 --- a/tests/main_test.py +++ b/tests/main_test.py @@ -25,6 +25,8 @@ def test_main_noop(tmpdir, capsys): x=version_info def f(): global x, y + +f'hello snowman: \\N{SNOWMAN}' ''' f = tmpdir.join('f.py') f.write(s)