flake8 --enable-extensions problem.
% flake8 --version
3.0.4 (pyflakes: 1.2.3, mccabe: 0.5.2, pycodestyle: 2.0.0) CPython 3.5.2+ on Linux
Originally posted on the code-quality mailing list, with some follow up with @sigmavirus24
I am working on a plugin which provides a checker for GNU Mailman style imports. I'm having trouble getting flake8 v3's --enable-extensions
feature to work. Here's what I'm doing:
class ImportOrder:
name = 'flufl-import-order'
version = '0.2'
off_by_default = True
def __init__(self, tree, filename):
# ...
def run(self):
# ...
and it registers itself via:
setup(
# ...
entry_points={
'flake8.extensions': ['U4 = flufl.testhelpers.imports:ImportOrder'],
},
# ...
)
All of the plugin's error codes are U40X
and U41X
codes. What I'd like to be able to do is to tell users to add this to their tox.ini file to enable the plugin:
[flake8]
enable-extensions = U4
But this doesn't seem to work. I know that the extension runs just fine if I don't include the off_by_default=True
class attribute, but as soon as I add that, there doesn't seem to be a way to re-enable it. I don't want to have to tell users that the plugin always runs and that they have to suppress the U4 errors if they don't want it.
I've pdb'd through the code and have some additional information.
My plugin is getting called, and is reported its errors, but the StyleGuide
in place has a different self._extended_selected
depending on whether my plugin's off_by_default
is True or False.
In the False case, I see my 'U4' code in options.extended_default_select
. In the True case, my code is not in that set. In the True case, is_user_selected()
returns Ignored.Implicitly
because of that, while in the False case it returns Selected.Implicitly
. That's why I see the error code in the False case but not in the True case.
What appears to be happening is this:
With off_by_default=False
, I can see that Optionmanager.extend_default_select()
gets called with my error code before the StyleGuide
instance is created (where the options are passed in to the __init__()
). With off_by_default=True
, it seems like my error code gets passed in after the StyleGuide
gets instantiated. Thus, when the StyleGuide
sees options.extended_default_select
, it has a different set of error codes in
the True or False case, and thus it either gets reported or not as described above.