@@ -1620,32 +1620,32 @@ def python_3000_invalid_escape_sequence(logical_line, tokens, noqa):
1620
1620
'U' ,
1621
1621
]
1622
1622
1623
- for token_type , text , start , end , line in tokens :
1624
- if token_type == tokenize .STRING :
1625
- start_line , start_col = start
1626
- quote = text [- 3 :] if text [- 3 :] in ('"""' , "'''" ) else text [- 1 ]
1623
+ prefixes = []
1624
+ for token_type , text , start , _ , _ in tokens :
1625
+ if token_type in {tokenize .STRING , FSTRING_START }:
1627
1626
# Extract string modifiers (e.g. u or r)
1628
- quote_pos = text .index (quote )
1629
- prefix = text [:quote_pos ].lower ()
1630
- start = quote_pos + len (quote )
1631
- string = text [start :- len (quote )]
1627
+ prefixes .append (text [:text .index (text [- 1 ])].lower ())
1632
1628
1633
- if 'r' not in prefix :
1634
- pos = string .find ('\\ ' )
1629
+ if token_type in {tokenize .STRING , FSTRING_MIDDLE }:
1630
+ if 'r' not in prefixes [- 1 ]:
1631
+ start_line , start_col = start
1632
+ pos = text .find ('\\ ' )
1635
1633
while pos >= 0 :
1636
1634
pos += 1
1637
- if string [pos ] not in valid :
1638
- line = start_line + string .count ('\n ' , 0 , pos )
1635
+ if text [pos ] not in valid :
1636
+ line = start_line + text .count ('\n ' , 0 , pos )
1639
1637
if line == start_line :
1640
- col = start_col + len ( prefix ) + len ( quote ) + pos
1638
+ col = start_col + pos
1641
1639
else :
1642
- col = pos - string .rfind ('\n ' , 0 , pos ) - 1
1640
+ col = pos - text .rfind ('\n ' , 0 , pos ) - 1
1643
1641
yield (
1644
1642
(line , col - 1 ),
1645
- "W605 invalid escape sequence '\\ %s'" %
1646
- string [pos ],
1643
+ f"W605 invalid escape sequence '\\ { text [pos ]} '"
1647
1644
)
1648
- pos = string .find ('\\ ' , pos + 1 )
1645
+ pos = text .find ('\\ ' , pos + 1 )
1646
+
1647
+ if token_type in {tokenize .STRING , FSTRING_END }:
1648
+ prefixes .pop ()
1649
1649
1650
1650
1651
1651
########################################################################
0 commit comments