Skip to content

Commit

Permalink
Drop support for Python 2.x (#198)
Browse files Browse the repository at this point in the history
  • Loading branch information
jparise authored May 19, 2022
1 parent 53e731f commit d51ab38
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 0 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
48 changes: 5 additions & 43 deletions src/pep8ext_naming.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
__version__ = '0.12.1'

PYTHON_VERSION = sys.version_info[:3]
PY2 = PYTHON_VERSION[0] == 2

CLASS_METHODS = frozenset((
'__new__',
Expand All @@ -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]
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
13 changes: 1 addition & 12 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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 =
Expand Down

0 comments on commit d51ab38

Please sign in to comment.