diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f246487..381d3f8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [2.7, 3.7, 3.8, 3.9, "3.10", pypy-2.7, pypy-3.7] + python-version: [3.7, 3.8, 3.9, "3.10", pypy-3.7] steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} diff --git a/setup.py b/setup.py index 8fd4807..d099e4e 100644 --- a/setup.py +++ b/setup.py @@ -59,8 +59,6 @@ def run_tests(self): 'License :: OSI Approved :: MIT License', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Topic :: Software Development :: Libraries :: Python Modules', 'Topic :: Software Development :: Quality Assurance', diff --git a/src/pep8ext_naming.py b/src/pep8ext_naming.py index 0fc57a8..b389914 100644 --- a/src/pep8ext_naming.py +++ b/src/pep8ext_naming.py @@ -18,7 +18,6 @@ __version__ = '0.12.1' PYTHON_VERSION = sys.version_info[:3] -PY2 = PYTHON_VERSION[0] == 2 CLASS_METHODS = frozenset(( '__new__', @@ -28,31 +27,14 @@ METACLASS_BASES = frozenset(('type', 'ABCMeta')) # Node types which may contain class methods -METHOD_CONTAINER_NODES = {ast.If, ast.While, ast.For, ast.With} +METHOD_CONTAINER_NODES = {ast.If, ast.While, ast.For, ast.With, ast.Try} FUNC_NODES = (ast.FunctionDef,) -if PY2: - METHOD_CONTAINER_NODES |= {ast.TryExcept, ast.TryFinally} -else: - METHOD_CONTAINER_NODES |= {ast.Try} - if PYTHON_VERSION > (3, 5): FUNC_NODES += (ast.AsyncFunctionDef,) METHOD_CONTAINER_NODES |= {ast.AsyncWith, ast.AsyncFor} -if PY2: - def _unpack_args(args): - ret = [] - for arg in args: - if isinstance(arg, ast.Tuple): - ret.extend(_unpack_args(arg.elts)) - else: - ret.append((arg, arg.id)) - return ret - - def get_arg_name_tuples(node): - return _unpack_args(node.args.args) -elif PYTHON_VERSION < (3, 8): +if PYTHON_VERSION < (3, 8): def get_arg_name_tuples(node): groups = (node.args.args, node.args.kwonlyargs) return [(arg, arg.arg) for args in groups for arg in args] @@ -373,10 +355,7 @@ class FunctionArgNamesCheck(BaseASTCheck): def visit_functiondef(self, node, parents, ignore=None): def arg_name(arg): - try: - return arg, arg.arg - except AttributeError: # PY2 - return node, arg + return (arg, arg.arg) if arg else (node, arg) for arg, name in arg_name(node.args.vararg), arg_name(node.args.kwarg): if name is None or _ignored(name, ignore): @@ -491,11 +470,6 @@ def visit_namedexpr(self, node, parents, ignore): visit_annassign = visit_namedexpr def visit_with(self, node, parents, ignore): - if PY2: - for error in self._find_errors( - node.optional_vars, parents, ignore): - yield error - return for item in node.items: for error in self._find_errors( item.optional_vars, parents, ignore): @@ -553,23 +527,11 @@ def _extract_names(assignment_target): elif element_type in (ast.Tuple, ast.List): for n in _extract_names(element): yield n - elif not PY2 and element_type is ast.Starred: # PEP 3132 + elif element_type is ast.Starred: # PEP 3132 for n in _extract_names(element.value): yield n elif target_type is ast.ExceptHandler: - if PY2: - # Python 2 supports unpacking tuple exception values. - if isinstance(assignment_target.name, ast.Tuple): - for name in assignment_target.name.elts: - yield name.id - elif isinstance(assignment_target.name, ast.Attribute): - # Python 2 also supports assigning an exception to an attribute - # eg. except Exception as obj.attr - yield assignment_target.name.attr - else: - yield assignment_target.name.id - else: - yield assignment_target.name + yield assignment_target.name def is_mixed_case(name): diff --git a/tox.ini b/tox.ini index 211572c..8391437 100644 --- a/tox.ini +++ b/tox.ini @@ -1,28 +1,17 @@ [tox] -envlist = py27,py27-flake8,py35,py36,py37,py38,py39,py310,py310-flake8,pypy,pypy3 +envlist = py37,py38,py39,py310,py310-flake8,pypy3 [gh-actions] python = - 2.7: py27, py27-flake8 - 3.5: py35 - 3.6: py36 3.7: py37 3.8: py38 3.9: py39 3.10: py310, py310-flake8 - pypy-2.7: pypy2 pypy-3.7: pypy3 [testenv] commands = python run_tests.py -[testenv:py27-flake8] -deps = - flake8 >= 3.9.1 -commands = - flake8 {posargs} src/pep8ext_naming.py - python setup.py check --restructuredtext - [testenv:py310-flake8] basepython = python3.10 deps =