Skip to content

Commit

Permalink
MAINT: add stacklevel argument to warnings.warn
Browse files Browse the repository at this point in the history
This fixes B028.

> No explicit stacklevel keyword argument found. The warn method from the
> warnings module uses a stacklevel of 1 by default. This will only show a stack
> trace for the line on which the warn method is called. It is therefore
> recommended to use a stacklevel of 2 or greater to provide more information to
> the user.

I personally do not find this error very useful, but let's just pass the
stacklevel argument and consider ignoring the error globally if we get
more cases like this where this is the intended behavior.

Signed-off-by: Filipe Laíns <lains@riseup.net>
  • Loading branch information
FFY00 committed Mar 21, 2023
1 parent d854680 commit 4552720
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mesonpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ def _init_colors() -> Dict[str, str]:
"""
if 'NO_COLOR' in os.environ:
if 'FORCE_COLOR' in os.environ:
warnings.warn('Both NO_COLOR and FORCE_COLOR environment variables are set, disabling color')
warnings.warn(
'Both NO_COLOR and FORCE_COLOR environment variables are set, disabling color',
stacklevel=1,
)
return _NO_COLORS
elif 'FORCE_COLOR' in os.environ or sys.stdout.isatty():
return _COLORS
Expand Down

0 comments on commit 4552720

Please sign in to comment.