Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format hex code in unicode escape sequences in string literals #2916

Merged
merged 24 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
add30b8
Format hex code in unicode escape sequences in string literals
Shivansh-007 Jan 30, 2022
483fc15
Format \N character name escapes with uppercased literals
Shivansh-007 Jan 31, 2022
cc48d2d
Fix formatting with correct length for each format
Shivansh-007 Mar 13, 2022
f1dbc96
Add changelog
Shivansh-007 Mar 13, 2022
ef442a6
Move feature to preview styling only
Shivansh-007 Mar 13, 2022
2ada012
Fix typo
Shivansh-007 Mar 13, 2022
125ebec
Change Match[AnyStr] to Match[str]
Shivansh-007 Mar 16, 2022
af86102
Make UNICODE_RE Final and accept multiline strings
Shivansh-007 Mar 16, 2022
69c9664
Reword regex comments to use 'character'
Shivansh-007 Mar 16, 2022
7d0e548
Merge remote-tracking branch 'upstream/main' into format/hex-code-lit…
Shivansh-007 Mar 16, 2022
52bd904
ITS RE.VERBOSE NOT RE.MULTILINE?!
Shivansh-007 Mar 16, 2022
a5c4e62
Merge branch 'main' into format/hex-code-literals
JelleZijlstra Mar 24, 2022
221995e
Update CHANGES.md
Shivansh-007 Mar 24, 2022
d4dde2e
Merge branch 'main' into format/hex-code-literals
JelleZijlstra Apr 2, 2022
3557faf
Merge branch 'main' into format/hex-code-literals
JelleZijlstra Dec 18, 2022
77a48e6
CR improvements
JelleZijlstra Dec 18, 2022
1b9d5fd
fix lint
JelleZijlstra Dec 18, 2022
3c24427
fix my sloppy code
JelleZijlstra Dec 18, 2022
9f35b61
fix the new test; \U requires exactly 8 digits
JelleZijlstra Dec 18, 2022
27d2d86
fix \N escapes
JelleZijlstra Dec 18, 2022
420a8f9
add a test
JelleZijlstra Dec 18, 2022
296cdb9
bytes tests
JelleZijlstra Dec 18, 2022
625c085
Merge branch 'main' into format/hex-code-literals
JelleZijlstra Dec 29, 2022
1511959
Merge branch 'main' into format/hex-code-literals
JelleZijlstra Dec 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move feature to preview styling only
  • Loading branch information
Shivansh-007 committed Mar 13, 2022
commit ef442a6d83577348c71317826fc01fff7fd31a35
4 changes: 3 additions & 1 deletion src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ def visit_factor(self, node: Node) -> Iterator[Line]:
yield from self.visit_default(node)

def visit_STRING(self, leaf: Leaf) -> Iterator[Line]:
normalize_unicode_escape_sequences(leaf)
if Preview.hex_codes_in_unicode_sequences in self.mode:
# Preview style only
Shivansh-007 marked this conversation as resolved.
Show resolved Hide resolved
normalize_unicode_escape_sequences(leaf)

if is_docstring(leaf) and "\\\n" not in leaf.value:
# We're ignoring docstrings with backslash newline escapes because changing
Expand Down
1 change: 1 addition & 0 deletions src/black/mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class Preview(Enum):

string_processing = auto()
hug_simple_powers = auto()
hex_codes_in_unicode_sequences = auto()
Shivansh-007 marked this conversation as resolved.
Show resolved Hide resolved


class Deprecated(UserWarning):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
"fmtskip4",
"fmtskip5",
"fmtskip6",
"format_unicode_escape_seq",
"fstring",
"function",
"function2",
Expand Down Expand Up @@ -76,6 +75,7 @@
# string processing
"cantfit",
"comments7",
"format_unicode_escape_seq",
"long_strings",
"long_strings__edge_case",
"long_strings__regression",
Expand Down