[New-bugs-announce] [issue43527] Support full stack trace extraction in warnings.

Xavier Morel report at bugs.python.org
Wed Mar 17 05:39:37 EDT 2021


New submission from Xavier Morel <xavier.morel at masklinn.net>:

When triggering warnings, it's possible to pass in a `stacklevel` in order to point to a more informative cause than the `warnings.warn` call. 

For instance `stacklevel=2` is a common one for DeprecationWarning in order to mark the call itself as deprecated in the caller's codebase.

The problem with this is that it's not transitive, so when a dependency triggers a warning it can be hard to know where that comes from in the codebase (at least without `-Werror` which can prevent reaching the interesting warning entirely), and whether this is an issue in the codebase (e.g. passing bytes where the library really works in terms of strings) or whether it would be possible to work around the warning by using some other API.

In that case, the ability to show a full stack trace from the `stacklevel` down is very useful to diagnose such issues.

Not quite sure how it would be managed though: I'd think this should be part of the warnings filter information, but the `stacklevel` currently isn't stored there, and it might be risky to extend the warnings filter with a 6th field).

----------
components: Library (Lib)
messages: 388914
nosy: xmorel
priority: normal
severity: normal
status: open
title: Support full stack trace extraction in warnings.
type: enhancement
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43527>
_______________________________________


More information about the New-bugs-announce mailing list