summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2021-12-27 13:49:57 -0500
committerGitHub <noreply@github.com>2021-12-27 13:49:57 -0500
commit5a6f3746532455c0fcb0b2a4350d58e89a832322 (patch)
tree1db32eeb4e8d2a9bc7f9b08cbc762b4d8225d98b
parent8b5c964321776b2fe8dfd25f4f18db0ffbdbd281 (diff)
parentb90935608da6600e6d1deef47e7f537fab04b609 (diff)
downloadpep8-5a6f3746532455c0fcb0b2a4350d58e89a832322.tar.gz
Merge pull request #1045 from dannysepler/delete-py2
Remove lingering < py3.6 code
-rwxr-xr-xpycodestyle.py30
-rw-r--r--testsuite/test_all.py3
-rw-r--r--testsuite/test_api.py17
3 files changed, 2 insertions, 48 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index c71071e..83069c5 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -55,18 +55,8 @@ import sys
import time
import tokenize
import warnings
-
-try:
- from functools import lru_cache
-except ImportError:
- def lru_cache(maxsize=128): # noqa as it's a fake implementation.
- """Does not really need a real a lru_cache, it's just
- optimization, so let's just do nothing here. Python 3.2+ will
- just get better performances, time to upgrade?
- """
- return lambda function: function
-
from fnmatch import fnmatch
+from functools import lru_cache
from optparse import OptionParser
try:
@@ -301,12 +291,6 @@ def maximum_line_length(physical_line, max_line_length, multiline,
(len(chunks) == 2 and chunks[0] == '#')) and \
len(line) - len(chunks[-1]) < max_line_length - 7:
return
- if hasattr(line, 'decode'): # Python 2
- # The line could contain multi-byte characters
- try:
- length = len(line.decode('utf-8'))
- except UnicodeError:
- pass
if length > max_line_length:
return (max_line_length, "E501 line too long "
"(%d > %d characters)" % (length, max_line_length))
@@ -1459,12 +1443,6 @@ def comparison_type(logical_line, noqa):
Okay: if isinstance(obj, int):
E721: if type(obj) is type(1):
-
- When checking if an object is a string, keep in mind that it might
- be a unicode string too! In Python 2.3, str and unicode have a
- common base class, basestring, so you can do:
-
- Okay: if isinstance(obj, basestring):
"""
match = COMPARE_TYPE_REGEX.search(logical_line)
if match and not noqa:
@@ -1787,12 +1765,6 @@ def maximum_doc_length(logical_line, max_doc_length, noqa, tokens):
if prev_token is None or prev_token in SKIP_TOKENS:
lines = line.splitlines()
for line_num, physical_line in enumerate(lines):
- if hasattr(physical_line, 'decode'): # Python 2
- # The line could contain multi-byte characters
- try:
- physical_line = physical_line.decode('utf-8')
- except UnicodeError:
- pass
if start[0] + line_num == 1 and line.startswith('#!'):
return
length = len(physical_line)
diff --git a/testsuite/test_all.py b/testsuite/test_all.py
index 3508674..38b3c45 100644
--- a/testsuite/test_all.py
+++ b/testsuite/test_all.py
@@ -7,9 +7,6 @@ import unittest
import pycodestyle
from testsuite.support import init_tests, selftest, ROOT_DIR
-# Note: please only use a subset of unittest methods which were present
-# in Python 2.5: assert(True|False|Equal|NotEqual|Raises)
-
class PycodestyleTestCase(unittest.TestCase):
"""Test the standard errors and warnings (E and W)."""
diff --git a/testsuite/test_api.py b/testsuite/test_api.py
index ce2d33a..8dde32f 100644
--- a/testsuite/test_api.py
+++ b/testsuite/test_api.py
@@ -322,18 +322,6 @@ class APITestCase(unittest.TestCase):
# < 3.3 raises TypeError; >= 3.3 raises AttributeError
self.assertRaises(Exception, pep8style.check_files, [42])
- def test_check_unicode(self):
- # Do not crash if lines are Unicode (Python 2.x)
- pycodestyle.register_check(DummyChecker, ['Z701'])
- source = u'#\n'
-
- pep8style = pycodestyle.StyleGuide()
- count_errors = pep8style.input_file('stdin', lines=[source])
-
- self.assertFalse(sys.stdout)
- self.assertFalse(sys.stderr)
- self.assertEqual(count_errors, 0)
-
def test_check_nullbytes(self):
pycodestyle.register_check(DummyChecker, ['Z701'])
@@ -341,10 +329,7 @@ class APITestCase(unittest.TestCase):
count_errors = pep8style.input_file('stdin', lines=['\x00\n'])
stdout = sys.stdout.getvalue()
- if 'ValueError' in stdout: # pragma: no cover (python 3.5+)
- expected = "stdin:1:1: E901 ValueError"
- else: # pragma: no cover (< python3.5)
- expected = "stdin:1:1: E901 TypeError"
+ expected = "stdin:1:1: E901 ValueError"
self.assertTrue(stdout.startswith(expected),
msg='Output %r does not start with %r' %
(stdout, expected))