From 302d1ddb383eac42d27d18ee3d69d312c90f2569 Mon Sep 17 00:00:00 2001 From: Danny Sepler Date: Sun, 26 Dec 2021 17:56:40 -0500 Subject: Remove lingering py2 code --- pycodestyle.py | 29 +---------------------------- testsuite/test_all.py | 3 --- testsuite/test_api.py | 17 +---------------- 3 files changed, 2 insertions(+), 47 deletions(-) diff --git a/pycodestyle.py b/pycodestyle.py index c71071e..bc48e35 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -56,17 +56,8 @@ 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 +292,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 +1444,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 +1766,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)) -- cgit v1.2.1