New submission from Xavier Morel <xavier.mo...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue43527>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to