-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
STYLE "wrongplaced whitespace" rule doesn't error on its example of a bad string #40873
Comments
What I don't understand is the logic behind the lines pandas/scripts/validate_unwanted_patterns.py Lines 373 to 376 in 9ab55b4
Why should they return $ git diff
diff --git a/scripts/validate_unwanted_patterns.py b/scripts/validate_unwanted_patterns.py
index b6b038ae9d..369039de2c 100755
--- a/scripts/validate_unwanted_patterns.py
+++ b/scripts/validate_unwanted_patterns.py
@@ -370,10 +370,6 @@ def strings_with_wrong_placed_whitespace(
"""
if first_line.endswith(r"\n"):
return False
- elif first_line.startswith(" ") or second_line.startswith(" "):
- return False
- elif first_line.endswith(" ") or second_line.endswith(" "):
- return False
elif (not first_line.endswith(" ")) and second_line.startswith(" "):
return True
return False
$ pre-commit run unwanted-patterns-strings-with-wrong-placed-whitespace --all-files
Check for strings with wrong placed spaces...............................Passed |
The idea is that on multiline strings we always keep the spaces from a split in the same position (at the end). foo = ('this is '
'what we want')
bar = ('and this'
' is wrong') Then, I think there were cases with multiple spaces, like for indenting, inside the string. So we were checking that a single space existed, otherwise we consider the case ok. I don't remember about the line breaks. I thought these rules were well tested. I'm in my phone now, can't easily check, but aren't there tests that clarify what is doing with examples and make sure this works as expected? |
Thanks @datapythonista ! The tests miss quite a few lines: pandas/scripts/validate_unwanted_patterns.py Lines 87 to 88 in 735f40c
pandas/scripts/validate_unwanted_patterns.py Lines 371 to 372 in 735f40c
pandas/scripts/validate_unwanted_patterns.py Lines 375 to 376 in 735f40c
pandas/scripts/validate_unwanted_patterns.py Line 379 in 735f40c
Also, this test: pandas/scripts/tests/test_validate_unwanted_patterns.py Lines 212 to 216 in 735f40c
hits the lines pandas/scripts/validate_unwanted_patterns.py Lines 373 to 374 in 735f40c
though none of the pandas codebase does. I get that if the first string ends with pandas/scripts/validate_unwanted_patterns.py Lines 373 to 376 in 9ab55b4
Seeing as nothing in the pandas codebase hits them, I'd be inclined to remove them |
Seems to me that these two last But in any case, that was added for some case that wasn't working with the simple validation of |
IIRC the reason for those two
IIRC they did catch something in the codebase back then, but that was a year ago, I'm not really sure. |
The docstring reads
pandas/scripts/validate_unwanted_patterns.py
Lines 355 to 361 in 9ab55b4
yet this file doesn't error if the script is run on it:
Some other files which don't error, though I can't understand why:
Hi @ShaharNaveh @datapythonista - do you have any context you could provide on the trailing newline rule? I'm struggling to make sense of it - thanks :)
The text was updated successfully, but these errors were encountered: