Closed jayvdb closed 2 years ago
Recently I've been busy with the sharding library stuff but I'll look into this, thanks for the recommendation!
We could use the checker_state
from here to flag a print as being used in python 2 style and that we've already logged that it should be using future, that way we won't warn you more than once? If I understood checker_state
correctly.
checker_state
does look like it will provide state, but only within one check. As a result, and not surprising, the two plugins cant work together. One of the plugins will need to understand the other syntax element.
I checked the pep8 code, and checker_state
is not shared between checks of the same plugin, so the check would need to detect both future import and print function.
To understand future imports, flake8-future-import
has a FutureImportVisitor
which is an ast.NodeVisitor
approach. pep257
uses a more raw ast
solution, which was hardened in https://github.com/GreenSteam/pep257/pull/154 . After the flake8-print check switches to a logical line based check, neither of those two solutions will be usable. This plugin would need a regex based approach to future import detection. That shouldnt be too difficult to get 99% correct since we are given a logical line which simplifies some of the parsing. (After a bit of playing, it looks like pep8 does not split logical lines on ';' .)
It would be nice to force requiring
__future__.print_function
only when aprint
is found.And/Or somehow expose a 'uses print' flag per module, in a way that https://github.com/xZise/flake8-future-import/issues/1 could use the flag.