Skip to content

Ignore no-explicit-stacklevel/B028 if skip_file_prefixes is used #18011

@apple1417

Description

@apple1417

Summary

Setting skip_file_prefixes serves the same purpose as stacklevel, making sure the warning fires in a more informative place. It also actually implicitly sets stack level to at least 2.

When prefixes are supplied, stacklevel is implicitly overridden to be max(2, stacklevel).

This change was already made upstream PyCQA/flake8-bugbear#497

Sample code:

import os
import warnings

warnings.warn("test", skip_file_prefixes=(os.path.dirname(__file__),))
  • No explicit stacklevel keyword argument found (B028) [Ln 4, Col 1]

https://play.ruff.rs/f3bb6bb2-4d66-4eea-b86e-fa1c54c98f6b

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions