Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enable W on ruff #178

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
wants to merge 1 commit into from
Closed

Enable W on ruff #178

wants to merge 1 commit into from

Conversation

drhagen
Copy link
Contributor

@drhagen drhagen commented Jun 1, 2023

This used to be enabled when the project used flake8, but was lost in the migration to ruff because pycodestyle warnings are not enabled by default in ruff like they are in flake8.

@johnthagen
Copy link
Owner

johnthagen commented Jun 1, 2023

I see why Ruff did not enable W by default. All but one of the checks (invalid escape sequences) are handled by black --check or an E lint on line length, so it is pretty redundant.

Since Python 3.6, a DeprecationWarning is emitted for invalid escape sequences:

$ python3 -W default -c 'print(list("\z"))'
<string>:1: DeprecationWarning: invalid escape sequence '\z'
['\\', 'z']

This will be caught by pytest's treat-warnings-as-errors setting:

filterwarnings = [
   "error",
]

Moreover, Python 3.12 will be upgrading invalid escape sequences to an (on by default) SyntaxWarning , so perhaps we can simply defer this setting entirely to keep the Ruff configuration simpler:

A backslash-character pair that is not a valid escape sequence now generates a SyntaxWarning, instead of DeprecationWarning. For example, re.compile("\d+.\d+") now emits a SyntaxWarning ("\d" is an invalid escape sequence), use raw strings for regular expression: re.compile(r"\d+.\d+"). In a future Python version, SyntaxError will eventually be raised, instead of SyntaxWarning. (Contributed by Victor Stinner in gh-98401.)

@johnthagen johnthagen self-requested a review June 1, 2023 10:57
@drhagen
Copy link
Contributor Author

drhagen commented Jun 1, 2023

That's a good point. I got bit by invalid-escape-sequence and did not think about the others in the context of Black. I concur that this is not actually something worth turning on.

@drhagen drhagen closed this Jun 1, 2023
@drhagen drhagen deleted the enable-w-lint branch June 1, 2023 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants