Open quassy opened 1 year ago
@charliermarsh feel free to assign this to me, I can take a look. I'll put it under the RUF
linter. Want to get back into the AST, seems like we'll have to keep track of the scope block and ensure that all statements are associated with a scope?
It's probably too restrictive of a lint to include in RUF
, another case where we could use some kind of opt-in pedantic category.
I believe there is a flake8 plugn for this but I can't find it, also not a rule for ruff: Quite often I have to make sure that to avoid unintended side effects of imports all regular code should be guarded by functions, classes or
if __name__ == "__main__":
The inspection could look like this:
I's not safe to autofix because it will certainly change behaviour if you rely on the code being run on import. Manual fixes would be: