-
Notifications
You must be signed in to change notification settings - Fork 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
[pylint] Implement global-variable-undefined (W0601) #10820
base: main
Are you sure you want to change the base?
Conversation
181ccaa
to
4ea1948
Compare
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLW0601 | 14 | 14 | 0 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+14 -0 violations, +0 -0 fixes in 3 projects; 51 projects unchanged)
apache/airflow (+11 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ airflow/serialization/serialized_objects.py:1820:5: PLW0601 Global variable `HAS_KUBERNETES` is undefined at the module + airflow/settings.py:441:5: PLW0601 Global variable `Session` is undefined at the module + airflow/settings.py:442:5: PLW0601 Global variable `engine` is undefined at the module + airflow/settings.py:484:5: PLW0601 Global variable `Session` is undefined at the module + airflow/settings.py:485:5: PLW0601 Global variable `engine` is undefined at the module + airflow/settings.py:591:5: PLW0601 Global variable `engine` is undefined at the module + airflow/settings.py:592:5: PLW0601 Global variable `Session` is undefined at the module + airflow/settings.py:634:5: PLW0601 Global variable `engine` is undefined at the module + tests/executors/test_executor_loader.py:58:9: PLW0601 Global variable `ExecutorLoader` is undefined at the module + tests/listeners/class_listener.py:39:13: PLW0601 Global variable `stopped_component` is undefined at the module + tests/listeners/class_listener.py:71:13: PLW0601 Global variable `stopped_component` is undefined at the module
bokeh/bokeh (+2 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select ALL
+ examples/output/jupyter/push_notebook/Numba Image Example.ipynb:cell 18:2:5: PLW0601 Global variable `_last_kname` is undefined at the module + examples/output/jupyter/push_notebook/Numba Image Example.ipynb:cell 18:3:5: PLW0601 Global variable `_last_out` is undefined at the module
milvus-io/pymilvus (+1 -0 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview
+ _version_helper.py:92:9: PLW0601 Global variable `version` is undefined at the module
Changes by rule (1 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PLW0601 | 14 | 14 | 0 | 0 | 0 |
Does this break on wildcard imports? from os import *
def foo():
global system # W0601 should not be raised
system = lambda _: None |
Yes, it does. I have not found a function in ruff which resolves star-imports, e.g. there is F403 and F405 which are raised for star-imports and warn about "...unable to detect..." and "...may be undefined...". |
I think there's a way to detect if there's a star import in which case you could avoid creating any diagnostics (to avoid false-positives). The main open question to me are
|
@MichaReiser |
@tibor-reiss my preference would be that we don't flag any variables if a file contains a star import. I think there's already precedence for this in Ruff but I would need to search it to. @charliermarsh should know where to find it. |
6d1d4ca
to
68bb046
Compare
@MichaReiser thanks for feedback, I added the check for star imports together with a new test file. |
68bb046
to
5a61a5b
Compare
Hi @MichaReiser, this got lost in translation. I have updated now to the latest master, could you please have a look and let me know if something is still missing? |
Add pylint rule global-variable-undefined (W0601)
See #970 for rules
Test Plan:
cargo test