-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
F821 (undefined imports) false positives (?) in notebooks when using the %run magic #9644
Comments
@charliermarsh Is the fix you wrote for #9648 also supposed to deal with my issue? I still see the false positives unfortunately. Or had @MichaReiser labelled this as "wish" because imports through the |
The challenge is that it requires multi file analysis that ruff doesn't support yet. The analyzer needs to stop when seeing For now, you can try to use https://docs.astral.sh/ruff/settings/#builtins and define |
I'm guessing that my issue is similar to star imports (#8569) as I had also tried this. Looking forward to see the multi file analysis in ruff, this tool is awesome! Anyway, for my set of notebooks, I use a
to avoid having ruff erase the imports I make in the setup file. Thus, your solution seems like OK as a temporary workaround. I just have to make sure my |
Context
I have a setup file (e.g., IPython magic, display options for pandas, Seaborn visualization settings, etc) which I then import with the
%run
magic to avoid copy-pasting and making sure my settings are consistent between the different notebooks. Unfortunately, it leads to F821 (undefined imports) in the notebooks, which kinda defeats the purpose.Question
Is it a false positive? And if not, what is the proper way of achieving this sort of setup across a collection of notebooks while avoiding lintter/formatter errors?
MWE
Let's say I have a file called
mwe_setup.py
that contains:And then a file called
mwe.ipynb
that contains a single code cellThen running
ruff check mwe.ipynb
results inF821 Undefined name `plt`
.The text was updated successfully, but these errors were encountered: