mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-01 20:31:57 +00:00
Always prefer double quotes for docstrings and triple-quoted srings (#7680)
## Summary At present, `quote-style` is used universally. However, [PEP 8](https://peps.python.org/pep-0008/) and [PEP 257](https://peps.python.org/pep-0257/) suggest that while either single or double quotes are acceptable in general (as long as they're consistent), docstrings and triple-quoted strings should always use double quotes. In our research, the vast majority of Ruff users that enable the `flake8-quotes` rules only enable them for inline strings (i.e., non-triple-quoted strings). Additionally, many Black forks (like Blue and Pyink) use double quotes for docstrings and triple-quoted strings. Our decision for now is to always prefer double quotes for triple-quoted strings (which should include docstrings). Based on feedback, we may consider adding additional options (e.g., a `"preserve"` mode, to avoid changing quotes; or a `"multiline-quote-style"` to override this). Closes https://github.com/astral-sh/ruff/issues/7615. ## Test Plan `cargo test`
This commit is contained in:
parent
f62b4c801f
commit
695dbbc539
5 changed files with 84 additions and 68 deletions
|
|
@ -320,17 +320,17 @@ if True:
|
|||
b'This string will not include \
|
||||
backslashes or newline characters.'
|
||||
|
||||
b'''Multiline
|
||||
b"""Multiline
|
||||
String \"
|
||||
'''
|
||||
"""
|
||||
|
||||
b'''Multiline
|
||||
b"""Multiline
|
||||
String \'
|
||||
'''
|
||||
"""
|
||||
|
||||
b'''Multiline
|
||||
b"""Multiline
|
||||
String ""
|
||||
'''
|
||||
"""
|
||||
|
||||
b'''Multiline
|
||||
String """
|
||||
|
|
@ -346,9 +346,9 @@ String '''
|
|||
b"""Multiline
|
||||
String '"""
|
||||
|
||||
b'''Multiline
|
||||
b"""Multiline
|
||||
String \"\"\"
|
||||
'''
|
||||
"""
|
||||
|
||||
# String continuation
|
||||
|
||||
|
|
|
|||
|
|
@ -365,17 +365,17 @@ if True:
|
|||
'This string will not include \
|
||||
backslashes or newline characters.'
|
||||
|
||||
'''Multiline
|
||||
"""Multiline
|
||||
String \"
|
||||
'''
|
||||
"""
|
||||
|
||||
'''Multiline
|
||||
"""Multiline
|
||||
String \'
|
||||
'''
|
||||
"""
|
||||
|
||||
'''Multiline
|
||||
"""Multiline
|
||||
String ""
|
||||
'''
|
||||
"""
|
||||
|
||||
'''Multiline
|
||||
String """
|
||||
|
|
@ -391,9 +391,9 @@ String '''
|
|||
"""Multiline
|
||||
String '"""
|
||||
|
||||
'''Multiline
|
||||
"""Multiline
|
||||
String \"\"\"
|
||||
'''
|
||||
"""
|
||||
|
||||
# String continuation
|
||||
|
||||
|
|
@ -471,16 +471,16 @@ test_particular = [
|
|||
|
||||
# Regression test for https://github.com/astral-sh/ruff/issues/5893
|
||||
x = (
|
||||
'''aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'''
|
||||
'''bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'''
|
||||
"""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"""
|
||||
"""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"""
|
||||
)
|
||||
x = (
|
||||
f'''aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'''
|
||||
f'''bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'''
|
||||
f"""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"""
|
||||
f"""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"""
|
||||
)
|
||||
x = (
|
||||
b'''aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'''
|
||||
b'''bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'''
|
||||
b"""aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"""
|
||||
b"""bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"""
|
||||
)
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/7460
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue