[code-quality] Flake8 "globals"

Ben Finney ben+python at benfinney.id.au
Sun Feb 11 18:59:16 EST 2018


Chris Norman via code-quality
<code-quality at python.org> writes:

> I have a suggestion which I suspect is already implemented I just
> don't know how to find the option:

Based on my unsterstanding of your request, I think it is not
implemented and will not be.

> Using Flake8, I want to be able to set up globals like you can with
> eslint. This should allow me to say that there are globals present in
> the file which aren't currently there.
>
> I get that the use case is kind of non standard: I am evaling code […]

One reason why that is discouraged is exactly the problem you are
encountering. Code which does not exist at the time of static analysis
cannot be part of that static analysis.

By choosing to use ‘eval’ you are choosing to abandon the advantages of
static analysis; not only static analysis of the run-time evaluated code
but also of any code which interacts with that. A static analyser
depends on having access to the complete syntax tree of the run-time
program, without running it. You abandon that when you use ‘eval’.

For this reason, it is IMO best to acknowledge the severe reduction in
quality assurance that you impose, by choosing ‘eval’. Either ensure
everyone understands and accepts the reduction in effectiveness of code
quality tools; or re-structure the program not to use ‘eval’.

-- 
 \       “I disapprove of what you say, but I will defend to the death |
  `\     your right to say it.” —Evelyn Beatrice Hall, _The Friends of |
_o__)                                                  Voltaire_, 1906 |
Ben Finney



More information about the code-quality mailing list