Skip to content

no-explicit-stacklevel (B028) should allow no stacklevel when skip_file_prefixes is provided #22395

@abrahammurciano

Description

@abrahammurciano

Summary

According to the python documentation

The skip_file_prefixes keyword argument can be used to indicate which stack frames are ignored when counting stack levels. [...] When prefixes are supplied, stacklevel is implicitly overridden to be max(2, stacklevel).
[...]
Changed in version 3.12: Added skip_file_prefixes.

If skip_file_prefixes is provided, then the stacklevel is already set to at least 2, and the user has already explicitly skipped certain stack frames by prefix. The resulting warning will already give the caller more context about the warning since it will output a stack frame higher up than the one the warning was issued from, most likely outside of the issuing package (i.e. the caller's actual call).

Therefore I believe the B028 rule should be updated to allow either of the two parameters instead of only stacklevel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions