Skip to content

STYLE: replace unwanted-patterns-strings-to-concatenate with ruff #51406

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

Closed
MarcoGorelli opened this issue Feb 15, 2023 · 3 comments · Fixed by #51613
Closed

STYLE: replace unwanted-patterns-strings-to-concatenate with ruff #51406

MarcoGorelli opened this issue Feb 15, 2023 · 3 comments · Fixed by #51613
Assignees
Labels
Code Style Code style, linting, code_checks good first issue

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Feb 15, 2023

Task here is:

  1. in

pandas/pyproject.toml

Lines 201 to 215 in fe85cbf

select = [
# pyflakes
"F",
# pycodestyle
"E",
"W",
# flake8-2020
"YTT",
# flake8-bugbear
"B",
# flake8-quotes
"Q",
# pylint
"PLE", "PLR", "PLW",
]

add

# implicit string concatenation
"ISC",
  1. run pre-commit run ruff --all-files, and fix up everything it flags
  2. remove

- id: unwanted-patterns-strings-to-concatenate
name: Check for use of not concatenated strings
language: python
entry: python scripts/validate_unwanted_patterns.py --validation-type="strings_to_concatenate"
types_or: [python, cython]

  1. remove

def strings_to_concatenate(file_obj: IO[str]) -> Iterable[Tuple[int, str]]:
"""
This test case is necessary after 'Black' (https://github.com/psf/black),
is formatting strings over multiple lines.
For example, when this:
>>> foo = (
... "bar "
... "baz"
... )
Is becoming this:
>>> foo = ("bar " "baz")
'Black' is not considering this as an
issue (see https://github.com/psf/black/issues/1051),
so we are checking it here instead.
Parameters
----------
file_obj : IO
File-like object containing the Python code to validate.
Yields
------
line_number : int
Line number of unconcatenated string.
msg : str
Explanation of the error.
Notes
-----
GH #30454
"""
tokens: List = list(tokenize.generate_tokens(file_obj.readline))
for current_token, next_token in zip(tokens, tokens[1:]):
if current_token.type == next_token.type == token.STRING:
yield (
current_token.start[0],
(
"String unnecessarily split in two by black. "
"Please merge them manually."
),
)

  1. remove

@pytest.mark.parametrize(
"data, expected",
[
(
'msg = ("bar " "baz")',
[
(
1,
(
"String unnecessarily split in two by black. "
"Please merge them manually."
),
)
],
),
(
'msg = ("foo " "bar " "baz")',
[
(
1,
(
"String unnecessarily split in two by black. "
"Please merge them manually."
),
),
(
1,
(
"String unnecessarily split in two by black. "
"Please merge them manually."
),
),
],
),
],
)
def test_strings_to_concatenate(data, expected):
fd = io.StringIO(data.strip())
result = list(validate_unwanted_patterns.strings_to_concatenate(fd))
assert result == expected

  1. if there's anything else related to this old script which ruff now supplants, feel free to remove that too
@MarcoGorelli MarcoGorelli added Code Style Code style, linting, code_checks good first issue labels Feb 15, 2023
@natmokval
Copy link
Contributor

I would like to work on this.

@harsimran44
Copy link

i would like to work on this.

@MarcoGorelli
Copy link
Member Author

there's already a PR open sorry, please look for another issue to work on (e.g. https://github.com/pandas-dev/pandas/issues?q=is%3Aopen+is%3Aissue+label%3A%22good+first+issue%22)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Style Code style, linting, code_checks good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants