File tree 1 file changed +4
-5
lines changed
1 file changed +4
-5
lines changed Original file line number Diff line number Diff line change @@ -35,20 +35,19 @@ def create_valid_python_identifier(name: str) -> str:
35
35
------
36
36
SyntaxError
37
37
If the returned name is not a Python valid identifier, raise an exception.
38
- This can happen if the name includes characters that fall out of the range of
39
- (U+0001..U+007F).
40
38
"""
41
39
if name .isidentifier () and not iskeyword (name ):
42
40
return name
43
41
44
42
# Escape characters that fall outside the ASCII range (U+0001..U+007F).
45
43
# GH 49633
46
- c_escaped_gen = (
47
- "" .join (chr (b ) for b in c .encode ("ascii" , "backslashreplace" )) for c in name
44
+ gen = (
45
+ (c , "" .join (chr (b ) for b in c .encode ("ascii" , "backslashreplace" )))
46
+ for c in name
48
47
)
49
48
name = "" .join (
50
49
c_escaped .replace ("\\ " , "_UNICODE_" if c != c_escaped else "_BACKSLASH_" )
51
- for c , c_escaped in zip ( name , c_escaped_gen )
50
+ for c , c_escaped in gen
52
51
)
53
52
54
53
# Create a dict with the special characters and their replacement string.
You can’t perform that action at this time.
0 commit comments