You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PyLint allows users to pass --allow-global-unused-variables=n(o) option to catch not only function scope unused variables, but also module scope variables. This would modify rule F841: Unused Variable.
I would like to implement this.
Now there is a question that I would like to have answered before committing and perhaps open a discussion on it, if no clear answer is available.
Is 1-to-1 (or let's say bug-for-bug) parity with PyLint desirable?
PyLint has some undesirable behaviour, for example reporting class definitions not used in the same file as the definition as "unused variables" (in our code base and probably most code bases, it is fairly normal to have classes defined in one file and using them in another). I would prefer to define a "global-unused-variable" as not within function scope, not within class scope, not within generator/lambda scope and unused.
As mentioned above, PyLint reports the classes as unused (at least in our code base), and so it seems that it does not check this between files.
As such, I think Ruff is capable of checking whether a Module scoped variable that is not in a Function, Class, Generator or a Lambda, is unused and reporting it (given 'allow-global-unused-variables = false' is set in ruff.toml or other config file). In fact, I've got it working more or less on our codebase, just need to check whether the behaviour is in line with my expectations.
Please let me know if I'm wrong and what the opinion on PyLint parity is.
The text was updated successfully, but these errors were encountered:
Your implementation is what I would expect. I would be annoyed by the pylint behavior.
Recently an unused global var caused bug for me. Found this issue while searching for "why is this not reported?" So, I'm +1 on this feature being implemented.
PyLint allows users to pass --allow-global-unused-variables=n(o) option to catch not only function scope unused variables, but also module scope variables. This would modify rule F841: Unused Variable.
I would like to implement this.
Now there is a question that I would like to have answered before committing and perhaps open a discussion on it, if no clear answer is available.
Is 1-to-1 (or let's say bug-for-bug) parity with PyLint desirable?
PyLint has some undesirable behaviour, for example reporting class definitions not used in the same file as the definition as "unused variables" (in our code base and probably most code bases, it is fairly normal to have classes defined in one file and using them in another). I would prefer to define a "global-unused-variable" as not within function scope, not within class scope, not within generator/lambda scope and unused.
As mentioned above, PyLint reports the classes as unused (at least in our code base), and so it seems that it does not check this between files.
As such, I think Ruff is capable of checking whether a Module scoped variable that is not in a Function, Class, Generator or a Lambda, is unused and reporting it (given 'allow-global-unused-variables = false' is set in ruff.toml or other config file). In fact, I've got it working more or less on our codebase, just need to check whether the behaviour is in line with my expectations.
Please let me know if I'm wrong and what the opinion on PyLint parity is.
The text was updated successfully, but these errors were encountered: