Skip to content

Commit 4552720

Browse files
committed
MAINT: add stacklevel argument to warnings.warn
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 <[email protected]>
1 parent d854680 commit 4552720

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

mesonpy/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ def _init_colors() -> Dict[str, str]:
115115
"""
116116
if 'NO_COLOR' in os.environ:
117117
if 'FORCE_COLOR' in os.environ:
118-
warnings.warn('Both NO_COLOR and FORCE_COLOR environment variables are set, disabling color')
118+
warnings.warn(
119+
'Both NO_COLOR and FORCE_COLOR environment variables are set, disabling color',
120+
stacklevel=1,
121+
)
119122
return _NO_COLORS
120123
elif 'FORCE_COLOR' in os.environ or sys.stdout.isatty():
121124
return _COLORS

0 commit comments

Comments
 (0)