Format bytes string (#6166)

<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

Format bytes string

Closes #6064

## Test Plan

Added a fixture based on string's one
This commit is contained in:
Luc Khai Hai 2023-07-31 17:46:40 +09:00 committed by GitHub
parent de898c52eb
commit b95fc6d162
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 577 additions and 89 deletions

View file

@ -0,0 +1,8 @@
[
{
"quote_style": "double"
},
{
"quote_style": "single"
}
]

View file

@ -0,0 +1,120 @@
b"' test"
b'" test'
b"\" test"
b'\' test'
# Prefer single quotes for string with more double quotes
b"' \" \" '' \" \" '"
# Prefer double quotes for string with more single quotes
b'\' " " \'\' " " \''
# Prefer double quotes for string with equal amount of single and double quotes
b'" \' " " \'\''
b"' \" '' \" \""
b"\\' \"\""
b'\\\' ""'
b"Test"
B"Test"
rb"Test"
Rb"Test"
b'This string will not include \
backslashes or newline characters.'
if True:
b'This string will not include \
backslashes or newline characters.'
b"""Multiline
String \"
"""
b'''Multiline
String \'
'''
b'''Multiline
String ""
'''
b'''Multiline
String """
'''
b'''Multiline
String "'''
b"""Multiline
String '''
"""
b"""Multiline
String '"""
b'''Multiline
String \"\"\"
'''
# String continuation
b"Let's" b"start" b"with" b"a" b"simple" b"example"
b"Let's" b"start" b"with" b"a" b"simple" b"example" b"now repeat after me:" b"I am confident" b"I am confident" b"I am confident" b"I am confident" b"I am confident"
(
b"Let's" b"start" b"with" b"a" b"simple" b"example" b"now repeat after me:" b"I am confident" b"I am confident" b"I am confident" b"I am confident" b"I am confident"
)
if (
a + b"Let's"
b"start"
b"with"
b"a"
b"simple"
b"example"
b"now repeat after me:"
b"I am confident"
b"I am confident"
b"I am confident"
b"I am confident"
b"I am confident"
):
pass
if b"Let's" b"start" b"with" b"a" b"simple" b"example" b"now repeat after me:" b"I am confident" b"I am confident" b"I am confident" b"I am confident" b"I am confident":
pass
(
# leading
b"a" # trailing part comment
# leading part comment
b"b" # trailing second part comment
# trailing
)
test_particular = [
# squares
b'1.00000000100000000025',
b'1.0000000000000000000000000100000000000000000000000' #...
b'00025',
b'1.0000000000000000000000000000000000000000000010000' #...
b'0000000000000000000000000000000000000000025',
]
# Parenthesized string continuation with messed up indentation
{
"key": (
[],
b'a'
b'b'
b'c'
)
}