4 ms·
Pylint complains about: foo = functools.partial(bar, 'baz') because it thinks foo is a global constant and thus should be upcased. It can DIAF.
by emidln 10y ago
Pylint complains about:
foo = functools.partial(bar, 'baz')
because it thinks foo is a global constant and thus should be upcased. It can DIAF.
- tclancy 10y agoThis is exactly why it has ignore flags. Remember Python's attitude is "explicit is better than implicit": if you know what you are doing, you just put a flag over it. pylint is trying to catch the cases where a person didn't know what they're doing. I'd rather have to add a flag than have it miss those.
- gbog 10y agoAre you not in the module's global scope? If you are pylint is right and you wrong, you need to move this line inside a function or a class. There should be no code running at module level. Here you might argue that this is akin to a decorator, and that bar will not be called, so yes it is a corner case, but the main rule (only allow consts at module level) is still useful, and I'd say vital even.
- emidln 10y agoThis is not 'akin to a decorator', it's is partial function! Do you name your functions: def THIS_IS_IN_GLOBAL_SCOPE(): ... Of course you don't! Then why would you consider forcing someone to write this: def bar(spam, eggs): print spam, eggs def foo(eggs): return bar('baz', eggs) Which even manages to lose information, hence why functools.partial exists in the first place. This is bad because readers now see FOO and think it's a constant: FOO = functools.partial(bar, 'baz')