8000 `DeprecationWarning` for deprecated attributes should probably use stacklevel 2 · Issue #86 · pyasn1/pyasn1 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

DeprecationWarning for deprecated attributes should probably use stacklevel 2 #86

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
Daverball opened this issue Mar 25, 2025 · 0 comments

Comments

@Daverball
Copy link
Daverball commented Mar 25, 2025

E.g.

warnings.warn(f"{attr} is deprecated. Please use {newAttr} instead.", DeprecationWarning)

Currently the stack trace for these warnings will start at the definition site, when really they should start at the usage site. This would match the recommendation given in the warnings module and is also the stacklevel @warnings.deprecated uses by default for calling a deprecated function.

Pytest will only show the first stacklevel in its warnings summary by default and will be the main way people encounter these warnings, since they're off by default, so it's best for the first stack level to be indicative of where something needs to change in order for the warning to go away. It also makes it easier to filter the warning for specific third party packages that have yet still to make the transition, rather than ignoring the warning globally and risk regressions in your own code.

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

No branches or pull requests

1 participant
0