Skip to content
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

Merged
merged 4 commits into from Jan 11, 2023

Conversation

cadedaniel
Copy link
Member

@cadedaniel cadedaniel commented Jan 7, 2023

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:

... 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>
pytest.ini Show resolved Hide resolved
@@ -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]
Copy link
Member Author

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

Copy link
Member Author

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: Cade Daniel <cade@anyscale.com>
@cadedaniel cadedaniel force-pushed the fix-newer-python-syntax-errors branch from 84678ee to 1d4ca4a Compare January 8, 2023 03:26
@cadedaniel cadedaniel force-pushed the fix-newer-python-syntax-errors branch from 1d4ca4a to e4b9651 Compare January 8, 2023 03:32
@cadedaniel cadedaniel changed the title [Draft] [Fail on pytest warnings 1/n] Marking strings with invalid escape sequences as raw strings [Fail on pytest warnings 1/n] Marking strings with invalid escape sequences as raw strings Jan 9, 2023
@cadedaniel cadedaniel marked this pull request as ready for review January 9, 2023 06:02
@cadedaniel cadedaniel added the core Issues that should be addressed in Ray Core label Jan 9, 2023
pytest.ini Outdated Show resolved Hide resolved
Copy link
Contributor

@rkooo567 rkooo567 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice PR!

pytest.ini Outdated Show resolved Hide resolved
@rkooo567
Copy link
Contributor

(make sure to get approval from all stakeholders... I assume that's the most challenging part to merge the PR)

Copy link
Contributor

@clarkzinzow clarkzinzow left a 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.

Copy link
Contributor

@krfricke krfricke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one question

rllib/algorithms/marwil/marwil.py Show resolved Hide resolved
@rkooo567
Copy link
Contributor

@cadedaniel can you double check the failure is not related to this PR? If so, I can merge it

@rkooo567 rkooo567 added the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Jan 11, 2023
@cadedaniel
Copy link
Member Author

@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.

@cadedaniel cadedaniel removed the @author-action-required The PR author is responsible for the next step. Remove tag to send back to the reviewer. label Jan 11, 2023
@scv119 scv119 merged commit e54ff46 into ray-project:master Jan 11, 2023
@cadedaniel cadedaniel deleted the fix-newer-python-syntax-errors branch January 11, 2023 19:05
@cadedaniel
Copy link
Member Author

cadedaniel commented Jan 11, 2023

This breaks the tests test_annotations.py::test_deprecated , test_runtime_context.py::test_ids, and test_actor_group.py::test_actor_creation in master because I didn't have a recent change #31195. Fixing forward in #31603, if there are more breakages then we should revert.

AmeerHajAli pushed a commit that referenced this pull request Jan 12, 2023
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues that should be addressed in Ray Core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants