From 743b26c964cd5032776c85b75610a3a329ae23cc Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Mon, 4 Feb 2019 10:29:09 -0800 Subject: [PATCH 1/2] Fix ignore-names option initialization cls.ignore_names starts life as a list, which is used as the default value for the ignore-names option, and then it becomes a frozenset() once the option is set. Unfortunately, when flake8's --config option is used, it appears we run those this sequence more than once, and that results in the frozenset() being passed as the option's default value, which breaks flake8. This change moves the default ignore-names list to a module-level constant alongside the other default lists. This avoids the problem described above and has the nice side-effect of making the code more consistent. --- CHANGELOG.rst | 5 +++++ src/pep8ext_naming.py | 23 ++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3299b87..cf0503c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,11 @@ Changes ======= +0.8.2 - 2019-02-04 +------------------ + +* Fix a problem with ``ignore-names`` option initialization. + 0.8.1 - 2019-02-04 ------------------ diff --git a/src/pep8ext_naming.py b/src/pep8ext_naming.py index 630b2c6..0d770d5 100644 --- a/src/pep8ext_naming.py +++ b/src/pep8ext_naming.py @@ -12,7 +12,7 @@ except ImportError: from flake8.util import ast, iter_child_nodes -__version__ = '0.8.1' +__version__ = '0.8.2' PYTHON_VERSION = sys.version_info[:3] PY2 = PYTHON_VERSION[0] == 2 @@ -83,6 +83,15 @@ class _FunctionType(object): METHOD = 'method' +_default_ignore_names = [ + 'setUp', + 'tearDown', + 'setUpClass', + 'tearDownClass', + 'setUpTestData', + 'failureException', + 'longMessage', + 'maxDiff'] _default_classmethod_decorators = ['classmethod'] _default_staticmethod_decorators = ['staticmethod'] @@ -102,15 +111,7 @@ class NamingChecker(object): version = __version__ decorator_to_type = _build_decorator_to_type( _default_classmethod_decorators, _default_staticmethod_decorators) - ignore_names = [ - 'setUp', - 'tearDown', - 'setUpClass', - 'tearDownClass', - 'setUpTestData', - 'failureException', - 'longMessage', - 'maxDiff'] + ignore_names = frozenset(_default_ignore_names) def __init__(self, tree, filename): self.visitors = BaseASTCheck._checks @@ -120,7 +121,7 @@ def __init__(self, tree, filename): @classmethod def add_options(cls, parser): options.register(parser, '--ignore-names', - default=cls.ignore_names, + default=_default_ignore_names, action='store', type='string', parse_from_config=True, From 3401bd1e83ff14131426399dc013e9860894ee8c Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Mon, 4 Feb 2019 11:15:42 -0800 Subject: [PATCH 2/2] Test --ignore-names for relevant error codes --- testsuite/N801.py | 3 +++ testsuite/N802.py | 7 +++++++ testsuite/N806.py | 3 +++ testsuite/N807.py | 3 +++ testsuite/N815.py | 3 +++ testsuite/N816.py | 2 ++ 6 files changed, 21 insertions(+) diff --git a/testsuite/N801.py b/testsuite/N801.py index fb29990..b2e9fb2 100644 --- a/testsuite/N801.py +++ b/testsuite/N801.py @@ -1,4 +1,7 @@ #: N801 +class notok(object): + pass +#: Okay(--ignore-names=notok) class notok(object): pass #: N801 diff --git a/testsuite/N802.py b/testsuite/N802.py index c609423..5cd959f 100644 --- a/testsuite/N802.py +++ b/testsuite/N802.py @@ -17,6 +17,9 @@ def go_od_(): def _go_od_(): pass #: N802:1:5 +def NotOK(): + pass +#: Okay(--ignore-names=NotOK) def NotOK(): pass #: Okay @@ -35,6 +38,10 @@ class ClassName(object): def __method__(self): pass #: N802 +class ClassName(object): + def notOk(self): + pass +#: Okay(--ignore-names=notOk) class ClassName(object): def notOk(self): pass diff --git a/testsuite/N806.py b/testsuite/N806.py index f6a2385..f71c8fc 100644 --- a/testsuite/N806.py +++ b/testsuite/N806.py @@ -22,6 +22,9 @@ def test2(): class Foo(object): def test3(self): Bad = 3 +#: Okay(--ignore-names=Bad) +def test(): + Bad = 1 #: Okay def good(): global Bad diff --git a/testsuite/N807.py b/testsuite/N807.py index f9d8c38..9b7dc12 100644 --- a/testsuite/N807.py +++ b/testsuite/N807.py @@ -35,6 +35,9 @@ class ClassName(object): def method(self): def __bad(): pass +#: Okay(--ignore-names=__bad) +def __bad(): + pass #: Okay def __dir__(): pass diff --git a/testsuite/N815.py b/testsuite/N815.py index 43a3bfd..ec4e4d8 100644 --- a/testsuite/N815.py +++ b/testsuite/N815.py @@ -19,3 +19,6 @@ class C: #: N815 class C: mixed_Case = 0 +#: Okay(--ignore-names=mixed_Case) +class C: + mixed_Case = 0 diff --git a/testsuite/N816.py b/testsuite/N816.py index 70d416f..6536bad 100644 --- a/testsuite/N816.py +++ b/testsuite/N816.py @@ -18,3 +18,5 @@ C6 = 0 #: Okay C_6 = 0. +#: Okay(--ignore-names=mixedCase) +mixedCase = 0