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

misc: ruff rules E741 and YTT204 #425

Merged
merged 1 commit into from
Feb 1, 2025
Merged

misc: ruff rules E741 and YTT204 #425

merged 1 commit into from
Feb 1, 2025

Conversation

cclauss
Copy link
Collaborator

@cclauss cclauss commented Jan 29, 2025

% ruff rule YTT204 sys-version-info-minor-cmp-int

% ruff rule E741

ambiguous-variable-name (E741)

Derived from the pycodestyle linter.

What it does

Checks for the use of the characters 'l', 'O', or 'I' as variable names.

Note: This rule is automatically disabled for all stub files
(files with .pyi extensions). The rule has little relevance for authors
of stubs: a well-written stub should aim to faithfully represent the
interface of the equivalent .py file as it exists at runtime, including any
ambiguously named variables in the runtime module.

Why is this bad?

In some fonts, these characters are indistinguishable from the
numerals one and zero. When tempted to use 'l', use 'L' instead.

Example

l = 0
O = 123
I = 42

Use instead:

L = 0
o = 123
i = 42

@cclauss
Copy link
Collaborator Author

cclauss commented Jan 29, 2025

Someone who knows Numpy should look at the issues at: ruff check select=NPY.

Also, ruff check select=E722

Why is this bad?

A bare except catches BaseException which includes
KeyboardInterrupt, SystemExit, Exception, and others. Catching
BaseException can make it hard to interrupt the program (e.g., with
Ctrl-C) and can disguise other problems.

@cclauss cclauss requested a review from mtrofin January 29, 2025 16:58
Copy link
Collaborator

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

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

LGTM.

From https://docs.astral.sh/ruff/rules/sys-version-info-minor-cmp-int/ outlining the motivation for YTT204 since I didn't see a large benefit at first:

Comparisons based on the current minor version number alone can cause subtle bugs and would likely lead to unintended effects if the Python major version number were ever incremented (e.g., to Python 4).

@cclauss cclauss merged commit 29d562c into google:main Feb 1, 2025
13 checks passed
@cclauss cclauss deleted the more-ruff branch February 1, 2025 07:59
Copy link

@Malekkimo Malekkimo left a comment

Choose a reason for hiding this comment

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


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.

4 participants