Disallow single-line implicit concatenated strings
Summary
I mainly put this up because I'm curious about the ecosystem changes. A proper implementation has to take the result of FormatImplicitConcatenatedFlat::new into account instead
of using the simplified approximation that forces the parent to expand when any string part is a raw or triple quoted string.
The goal of this change is to fix the formatter and ISC001 incompatibility by preventing that the formatter
ever introduces a single-line implicitly concatenated string.
Related to https://github.com/astral-sh/ruff/issues/8272
Test Plan
ruff-ecosystem results
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
ℹ️ ecosystem check detected format changes. (+18 -6 lines in 4 files in 3 projects; 51 projects unchanged)
bokeh/bokeh (+11 -3 lines across 2 files)
ruff format --preview
examples/styling/mathtext/latex_bessel.py~L21
width=700,
height=500,
title=(
- r"Bessel functions of the first kind: $$J_\alpha(x) = \sum_{m=0}^{\infty}" r"\frac{(-1)^m}{m!\:\Gamma(m+\alpha+1)} \left(\frac{x}{2}\right)^{2m+\alpha}$$"
+ r"Bessel functions of the first kind: $$J_\alpha(x) = \sum_{m=0}^{\infty}"
+ r"\frac{(-1)^m}{m!\:\Gamma(m+\alpha+1)} \left(\frac{x}{2}\right)^{2m+\alpha}$$"
),
)
p.x_range.range_padding = 0
src/bokeh/core/property/color.py~L126
Regex(r"^#[0-9a-fA-F]{4}$"),
Regex(r"^#[0-9a-fA-F]{6}$"),
Regex(r"^#[0-9a-fA-F]{8}$"),
- Regex(r"^rgba\(((25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*," r"\s*?){2}(25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*," r"\s*([01]\.?\d*?)\)"),
- Regex(r"^rgb\(((25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*," r"\s*?){2}(25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*?\)"),
+ Regex(
+ r"^rgba\(((25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*,"
+ r"\s*?){2}(25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*,"
+ r"\s*([01]\.?\d*?)\)"
+ ),
+ Regex(
+ r"^rgb\(((25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*,"
+ r"\s*?){2}(25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*?\)"
+ ),
Tuple(Byte, Byte, Byte),
Tuple(Byte, Byte, Byte, Percent),
RGB,
pandas-dev/pandas (+4 -2 lines across 1 file)
ruff format --preview
pandas/tests/tools/test_to_datetime.py~L1346
assert res is NaT
msg = "|".join([
- r'^time data "a" doesn\'t match format "%H:%M:%S". ' f"{PARSING_ERR_MSG}$",
+ r'^time data "a" doesn\'t match format "%H:%M:%S". '
+ f"{PARSING_ERR_MSG}$",
r'^Given date string "a" not likely a datetime$',
r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
f"{PARSING_ERR_MSG}$",
pandas/tests/tools/test_to_datetime.py~L1396
msg = "|".join([
r'^Given date string "a" not likely a datetime$',
- r'^time data "a" doesn\'t match format "%H:%M:%S". ' f"{PARSING_ERR_MSG}$",
+ r'^time data "a" doesn\'t match format "%H:%M:%S". '
+ f"{PARSING_ERR_MSG}$",
r'^unconverted data remains when parsing with format "%H:%M:%S": "9". '
f"{PARSING_ERR_MSG}$",
r"^second must be in 0..59: 00:01:99$",
rotki/rotki (+3 -1 lines across 1 file)
ruff format --preview
rotkehlchen/exchanges/coinbase.py~L68
LEGACY_RE: re.Pattern = re.compile(r"^[\w]+$")
NEW_RE: re.Pattern = re.compile(r"^organizations/[\w-]+/apiKeys/[\w-]+$")
PRIVATE_KEY_RE: re.Pattern = re.compile(
- r"^-----BEGIN EC PRIVATE KEY-----\n" r"[\w+/=\n]+" r"-----END EC PRIVATE KEY-----\n?$",
+ r"^-----BEGIN EC PRIVATE KEY-----\n"
+ r"[\w+/=\n]+"
+ r"-----END EC PRIVATE KEY-----\n?$",
re.MULTILINE,
)
I think this is a smart change. We should document it in the Black deviations though.
Thanks for the feedback. I plan to document the deviations as part of promoting the new style guide.