-
Notifications
You must be signed in to change notification settings - Fork 6k
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
[Fail on pytest warnings 1/n] Marking strings with invalid escape sequences as raw strings #31523
[Fail on pytest warnings 1/n] Marking strings with invalid escape sequences as raw strings #31523
Conversation
Signed-off-by: Cade Daniel <cade@anyscale.com>
@@ -66,7 +66,7 @@ def exec_worker(self, passthrough_args: List[str], language: Language): | |||
else: | |||
executable = "exec " | |||
|
|||
passthrough_args = [s.replace(" ", "\ ") for s in passthrough_args] | |||
passthrough_args = [s.replace(" ", r"\ ") for s in passthrough_args] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO(cade) make sure this passes tests, unclear what the purpose of this line is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rkooo567 do you know who has context on this line? I don't know enough about java args to say whether the fix is good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe @architkulkarni
Signed-off-by: Cade Daniel <cade@anyscale.com>
84678ee
to
1d4ca4a
Compare
1d4ca4a
to
e4b9651
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice PR!
(make sure to get approval from all stakeholders... I assume that's the most challenging part to merge the PR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving as Datasets codeowner! I double-checked and raw docstrings shouldn't result in different rendering of the docstrings.
Btw, another option is to escape the escapes in non-raw strings, but I think that raw strings are a better solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, one question
@cadedaniel can you double check the failure is not related to this PR? If so, I can merge it |
The failure is unrelated; I have #30388 but not the revert PR #31495. Let's merge. |
…uences as raw strings (#31523) Background Python deprecated invalid unicode escape sequences a while back (Python3.6) and they will start breaking in newer Pythons: Changed in version 3.6: Unrecognized escape sequences produce a DeprecationWarning. In a future Python version they will be a SyntaxWarning and eventually a SyntaxError. Docstrings and other strings that need \ et al. should be raw strings. Pytest? For reasons unclear to me, pytest encounters the SyntaxError when it instruments tests with improved assertions when its warnings are interpreted as failures. It's unclear how to ignore them (because they're marked as SyntaxErrors, which aren't warnings and can't be filtered). So, in this PR we fix the occurrences where we have invalid escape sequences. We have to do it in a separate PR from #31219 because our CI is using a prebuilt wheel instead of a per-PR wheel. #31479 tracks the work to fail on pytest warnings. Example offenders For example, see lines 406, 407, 412, and 413 here: ray/python/ray/data/grouped_dataset.py Lines 406 to 413 in 0c8b59d ... for i in range(100)]) \ # doctest: +SKIP ... .groupby(lambda x: x[0] % 3) \ # doctest: +SKIP ... .sum(lambda x: x[2]) # doctest: +SKIP >>> ray.data.range_table(100).groupby("value").sum() # doctest: +SKIP >>> ray.data.from_items([ # doctest: +SKIP ... {"A": i % 3, "B": i, "C": i**2} # doctest: +SKIP ... for i in range(100)]) \ # doctest: +SKIP ... .groupby("A") \ # doctest: +SKIP Signed-off-by: Cade Daniel <cade@anyscale.com>
Background
Python deprecated invalid unicode escape sequences a while back (Python3.6) and they will start breaking in newer Pythons:
Docstrings and other strings that need
\
et al. should be raw strings.Pytest?
For reasons unclear to me, pytest encounters the SyntaxError when it instruments tests with improved assertions when its warnings are interpreted as failures. It's unclear how to ignore them (because they're marked as SyntaxErrors, which aren't warnings and can't be filtered).
So, in this PR we fix the occurrences where we have invalid escape sequences. We have to do it in a separate PR from #31219 because our CI is using a prebuilt wheel instead of a per-PR wheel.
#31479 tracks the work to fail on pytest warnings.
Example offenders
For example, see lines 406, 407, 412, and 413 here:
ray/python/ray/data/grouped_dataset.py
Lines 406 to 413 in 0c8b59d