Skip to content

Commit 9c70655

Browse files
authored
Drop support for EOL Python 2.7, 3.5-3.6 (#191)
1 parent d51ab38 commit 9c70655

30 files changed

+317
-368
lines changed

run_tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import io
21
import optparse
32
import os
43
import platform
@@ -25,7 +24,7 @@ def main():
2524
errors = 0
2625
for filename in os.listdir('testsuite'):
2726
filepath = os.path.join('testsuite', filename)
28-
with io.open(filepath, encoding='utf8') as fd:
27+
with open(filepath, encoding='utf8') as fd:
2928
lines = list(fd)
3029
if not is_test_allowed(lines):
3130
continue

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,3 @@ project_urls =
33
Source=https://github.com/PyCQA/pep8-naming
44
Issues=https://github.com/PyCQA/pep8-naming/issues
55
Changelog=https://github.com/PyCQA/pep8-naming/blob/main/CHANGELOG.rst
6-
7-
[wheel]
8-
universal = 1

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
from __future__ import with_statement
31
from setuptools import setup
42
from setuptools.command.test import test as TestCommand
53

@@ -60,6 +58,11 @@ def run_tests(self):
6058
'Operating System :: OS Independent',
6159
'Programming Language :: Python',
6260
'Programming Language :: Python :: 3',
61+
'Programming Language :: Python :: 3.7',
62+
'Programming Language :: Python :: 3.8',
63+
'Programming Language :: Python :: 3.9',
64+
'Programming Language :: Python :: 3.10',
65+
'Programming Language :: Python :: 3 :: Only',
6366
'Topic :: Software Development :: Libraries :: Python Modules',
6467
'Topic :: Software Development :: Quality Assurance',
6568
],

src/pep8ext_naming.py

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""Checker of PEP-8 Naming Conventions."""
32
import sys
43
from collections import deque
@@ -27,12 +26,16 @@
2726
METACLASS_BASES = frozenset(('type', 'ABCMeta'))
2827

2928
# Node types which may contain class methods
30-
METHOD_CONTAINER_NODES = {ast.If, ast.While, ast.For, ast.With, ast.Try}
31-
FUNC_NODES = (ast.FunctionDef,)
32-
33-
if PYTHON_VERSION > (3, 5):
34-
FUNC_NODES += (ast.AsyncFunctionDef,)
35-
METHOD_CONTAINER_NODES |= {ast.AsyncWith, ast.AsyncFor}
29+
METHOD_CONTAINER_NODES = {
30+
ast.If,
31+
ast.While,
32+
ast.For,
33+
ast.With,
34+
ast.Try,
35+
ast.AsyncWith,
36+
ast.AsyncFor,
37+
}
38+
FUNC_NODES = (ast.FunctionDef, ast.AsyncFunctionDef)
3639

3740
if PYTHON_VERSION < (3, 8):
3841
def get_arg_name_tuples(node):
@@ -66,7 +69,7 @@ def _err(self, node, code, **kwargs):
6669
code_str = getattr(self, code)
6770
if kwargs:
6871
code_str = code_str.format(**kwargs)
69-
return lineno, col_offset + 1, '%s %s' % (code, code_str), self
72+
return lineno, col_offset + 1, f'{code} {code_str}', self
7073

7174

7275
def _ignored(name, ignore):
@@ -77,7 +80,7 @@ def _ignored(name, ignore):
7780
{'__doc__': "Base for AST Checks.", 'err': _err})
7881

7982

80-
class _FunctionType(object):
83+
class _FunctionType:
8184
CLASSMETHOD = 'classmethod'
8285
STATICMETHOD = 'staticmethod'
8386
FUNCTION = 'function'
@@ -110,7 +113,7 @@ def _build_decorator_to_type(classmethod_decorators, staticmethod_decorators):
110113
return decorator_to_type
111114

112115

113-
class NamingChecker(object):
116+
class NamingChecker:
114117
"""Checker of PEP-8 Naming Conventions."""
115118
name = 'naming'
116119
version = __version__
@@ -175,12 +178,10 @@ def run(self):
175178
return self.visit_tree(self._node) if self._node else ()
176179

177180
def visit_tree(self, node):
178-
for error in self.visit_node(node):
179-
yield error
181+
yield from self.visit_node(node)
180182
self.parents.append(node)
181183
for child in iter_child_nodes(node):
182-
for error in self.visit_tree(child):
183-
yield error
184+
yield from self.visit_tree(child)
184185
self.parents.pop()
185186

186187
def visit_node(self, node):
@@ -196,8 +197,7 @@ def visit_node(self, node):
196197
visitor_method = getattr(visitor, method, None)
197198
if visitor_method is None:
198199
continue
199-
for error in visitor_method(node, parents, ignore_names):
200-
yield error
200+
yield from visitor_method(node, parents, ignore_names)
201201

202202
def tag_class_functions(self, cls_node):
203203
"""Tag functions if they are methods, classmethods, staticmethods"""
@@ -458,40 +458,34 @@ def visit_assign(self, node, parents, ignore=None):
458458
if self.is_namedtupe(node.value):
459459
return
460460
for target in node.targets:
461-
for error in self._find_errors(target, parents, ignore):
462-
yield error
461+
yield from self._find_errors(target, parents, ignore)
463462

464463
def visit_namedexpr(self, node, parents, ignore):
465464
if self.is_namedtupe(node.value):
466465
return
467-
for error in self._find_errors(node.target, parents, ignore):
468-
yield error
466+
yield from self._find_errors(node.target, parents, ignore)
469467

470468
visit_annassign = visit_namedexpr
471469

472470
def visit_with(self, node, parents, ignore):
473471
for item in node.items:
474-
for error in self._find_errors(
475-
item.optional_vars, parents, ignore):
476-
yield error
472+
yield from self._find_errors(
473+
item.optional_vars, parents, ignore)
477474

478475
visit_asyncwith = visit_with
479476

480477
def visit_for(self, node, parents, ignore):
481-
for error in self._find_errors(node.target, parents, ignore):
482-
yield error
478+
yield from self._find_errors(node.target, parents, ignore)
483479

484480
visit_asyncfor = visit_for
485481

486482
def visit_excepthandler(self, node, parents, ignore):
487483
if node.name:
488-
for error in self._find_errors(node, parents, ignore):
489-
yield error
484+
yield from self._find_errors(node, parents, ignore)
490485

491486
def visit_generatorexp(self, node, parents, ignore):
492487
for gen in node.generators:
493-
for error in self._find_errors(gen.target, parents, ignore):
494-
yield error
488+
yield from self._find_errors(gen.target, parents, ignore)
495489

496490
visit_listcomp = visit_dictcomp = visit_setcomp = visit_generatorexp
497491

@@ -525,11 +519,9 @@ def _extract_names(assignment_target):
525519
if element_type is ast.Name:
526520
yield element.id
527521
elif element_type in (ast.Tuple, ast.List):
528-
for n in _extract_names(element):
529-
yield n
522+
yield from _extract_names(element)
530523
elif element_type is ast.Starred: # PEP 3132
531-
for n in _extract_names(element.value):
532-
yield n
524+
yield from _extract_names(element.value)
533525
elif target_type is ast.ExceptHandler:
534526
yield assignment_target.name
535527

testsuite/N801.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#: N801
2-
class notok(object):
2+
class notok:
33
pass
44
#: Okay(--ignore-names=notok)
5-
class notok(object):
5+
class notok:
66
pass
77
#: Okay(--ignore-names=*ok)
8-
class notok(object):
8+
class notok:
99
pass
1010
#: N801
11-
class Good(object):
12-
class notok(object):
11+
class Good:
12+
class notok:
1313
pass
1414
pass
1515
#: Okay
16-
class VeryGood(object):
16+
class VeryGood:
1717
pass
1818
#: N801:1:7
1919
class _:
@@ -52,3 +52,21 @@ class MEH__:
5252
#: Okay
5353
class __MEH__:
5454
pass
55+
#: Okay
56+
class Γ:
57+
pass
58+
#: Okay
59+
class ΓγΓγ:
60+
pass
61+
#: Okay
62+
class ΓγΓ6:
63+
pass
64+
#: Okay
65+
class :
66+
pass
67+
#: N801:1:7
68+
class γ:
69+
pass
70+
#: N801
71+
class :
72+
pass

testsuite/N801_py3.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

testsuite/N802.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@ def NotOK():
2929
def _():
3030
pass
3131
#: Okay
32-
class Foo(object):
32+
class Foo:
3333
def __method(self):
3434
pass
3535
#: Okay
36-
class Foo(object):
36+
class Foo:
3737
def __method__(self):
3838
pass
3939
#: Okay
40-
class ClassName(object):
40+
class ClassName:
4141
def __method__(self):
4242
pass
4343
#: N802
44-
class ClassName(object):
44+
class ClassName:
4545
def notOk(self):
4646
pass
4747
#: Okay(--ignore-names=notOk)
48-
class ClassName(object):
48+
class ClassName:
4949
def notOk(self):
5050
pass
5151
#: Okay(--ignore-names=*Ok)
52-
class ClassName(object):
52+
class ClassName:
5353
def notOk(self):
5454
pass
5555
#: Okay
@@ -84,3 +84,19 @@ def asyncTearDown(self):
8484
pass
8585
def setUpTestData(self):
8686
pass
87+
88+
#: Okay
89+
def γ(x):
90+
pass
91+
#: Okay
92+
def γ6(x):
93+
pass
94+
95+
#: Okay
96+
async def func(param1, param2):
97+
do_stuff()
98+
await some_coroutine()
99+
#: N802
100+
async def Func(param1, param2):
101+
do_stuff()
102+
await some_coroutine()

testsuite/N802_py3.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

testsuite/N802_py35.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

testsuite/N803.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def b18(a, *_):
5959
def b19(a, **_):
6060
pass
6161
#: N803:2:24
62-
class Test(object):
62+
class Test:
6363
def __init__(self, BAD):
6464
pass
6565

@@ -75,3 +75,41 @@ def f(*I):
7575
#: Okay(--ignore-names=I)
7676
def f(*I):
7777
I[''].think_therefore_i_am
78+
79+
#: Okay
80+
def compare(a, b, *, key=None):
81+
pass
82+
#: N803
83+
def compare(a, b, *, BAD=None):
84+
pass
85+
#: N803
86+
def compare(a, b, *VERY, bad=None):
87+
pass
88+
#: N803
89+
def compare(a, b, *ok, fine=None, **BAD):
90+
pass
91+
#: Okay
92+
def foo(α, ß, γ):
93+
pass
94+
#: Okay
95+
def foo(α, ß=''):
96+
pass
97+
#: Okay
98+
def foo(**κ):
99+
pass
100+
#: Okay
101+
def foo(*α):
102+
pass
103+
#: Okay
104+
def foo(**κ2):
105+
pass
106+
#: Okay
107+
def foo(*α2):
108+
pass
109+
110+
#: Okay
111+
async def compare(a, b, *, key=None):
112+
pass
113+
#: N803
114+
async def compare(a, b, *, BAD=None):
115+
pass

0 commit comments

Comments
 (0)