pylint icon indicating copy to clipboard operation
pylint copied to clipboard

Pylint should warn when global private variable (starting with ``_``) are unused

Open nmarrow opened this issue 7 years ago • 3 comments

Is your feature request related to a problem? Please describe

For a module defined like:

FOO = 'abc'
_BAR = 'xyz'

it would be great if pylint had an option to ignore the fact that FOO is unused, since it is "public", but still alert that _BAR is unused, since it is private to the module

Describe the solution you'd like

Would an additional configuration option for allow-global-unused-variables make sense? I'd like to have pylint let me know about unused global variables that it would consider protected, since in that case there's a higher chance the variable is truly unused.

nmarrow avatar Oct 16 '18 11:10 nmarrow

@nmarrow Yes, this sounds like a good idea. A separate option would be preferred.

PCManticore avatar Nov 27 '18 10:11 PCManticore

it would be great if pylint had an option to ignore the fact that FOO is unused

Isn't this already the case? If I understood this correctly, the new checker here must flag _BAR as unused.

satyanash avatar Oct 16 '21 06:10 satyanash

Right now pylint does not warn for any of those.

Pierre-Sassoulas avatar Oct 16 '21 08:10 Pierre-Sassoulas

So unused-protected-global seems like a new good checker here. But what about private globals? Should we check for both _BOO and __BOO?

clavedeluna avatar Nov 08 '22 11:11 clavedeluna

I think both are nice. _BOO can be a protected variable at the package level, I think the check would be costly (we have to check the whole repo for each global ?), Doesn't sound like something you want to launch all the time. The unused-private-global-variable is probably the most value / computation here and could be launched all the time.

Pierre-Sassoulas avatar Nov 08 '22 11:11 Pierre-Sassoulas