Skip to content

Avoid forgetting about stacklevel in warnings #2594

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Apr 30, 2025

I myself forget about it from time to time.

stacklevel=2 helps point the warning to the caller's code.

B028 only warns if no stacklevel is specified. stacklevel=1 is perfectly valid if explicit about it. It doesn't force a specific level, it just makes it so you can't forget.

This is optionally autofixable (ruff check --fix --unsafe-fixes) to stacklevel=2.

@Avasam Avasam force-pushed the Avoid-forgetting-about-stacklevel-in-warnings branch from 49f0fe8 to 51b5992 Compare April 30, 2025 23:03
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.

1 participant