Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warnings.warn(stacklevel=...) set too low #12

Closed
dangotbanned opened this issue Aug 31, 2024 · 0 comments · Fixed by #13
Closed

warnings.warn(stacklevel=...) set too low #12

dangotbanned opened this issue Aug 31, 2024 · 0 comments · Fixed by #13

Comments

@dangotbanned
Copy link
Member

Coming from vega/altair#3561 (comment)

May need to experiment with the correct level, but stacklevel=1 is almost always the wrong choice.
What would be helpful is reporting the code that triggered the warning.

In short, the call to warnings.warn appears here because stacklevel=1:

C:\Users\danie\AppData\Local\hatch\env\virtual\altair\CXM7NV9I\doc\Lib\site-packages\sphinxext_altair\altairplot.py:261: UserWarning: altair-plot: C:\Users\danie\Documents\GitHub\altair\doc\user_guide\interactions\bindings_widgets.rst:45 Code Execution failed:NameError: name 'alt' is not defined
  warnings.warn(message, stacklevel=1)

except Exception as err:
msg = (
f"altair-plot: {node['rst_source']}:{node['rst_lineno']} "
f"Code Execution failed: {type(err).__name__}: {err!s}"
)
if node["strict"]:
raise ValueError(msg) from err
else:
warnings.warn(msg, stacklevel=1)
raise nodes.SkipNode from err

Related

traitlets isn't involved here, but through the issue you can see the process of increasing stacklevel to find the source that raised the warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant