Skip to content

Commit 302d1dd

Browse files
committed
Remove lingering py2 code
1 parent 8b5c964 commit 302d1dd

File tree

3 files changed

+2
-47
lines changed

3 files changed

+2
-47
lines changed

pycodestyle.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,8 @@
5656
import tokenize
5757
import warnings
5858

59-
try:
60-
from functools import lru_cache
61-
except ImportError:
62-
def lru_cache(maxsize=128): # noqa as it's a fake implementation.
63-
"""Does not really need a real a lru_cache, it's just
64-
optimization, so let's just do nothing here. Python 3.2+ will
65-
just get better performances, time to upgrade?
66-
"""
67-
return lambda function: function
68-
6959
from fnmatch import fnmatch
60+
from functools import lru_cache
7061
from optparse import OptionParser
7162

7263
try:
@@ -301,12 +292,6 @@ def maximum_line_length(physical_line, max_line_length, multiline,
301292
(len(chunks) == 2 and chunks[0] == '#')) and \
302293
len(line) - len(chunks[-1]) < max_line_length - 7:
303294
return
304-
if hasattr(line, 'decode'): # Python 2
305-
# The line could contain multi-byte characters
306-
try:
307-
length = len(line.decode('utf-8'))
308-
except UnicodeError:
309-
pass
310295
if length > max_line_length:
311296
return (max_line_length, "E501 line too long "
312297
"(%d > %d characters)" % (length, max_line_length))
@@ -1459,12 +1444,6 @@ def comparison_type(logical_line, noqa):
14591444
14601445
Okay: if isinstance(obj, int):
14611446
E721: if type(obj) is type(1):
1462-
1463-
When checking if an object is a string, keep in mind that it might
1464-
be a unicode string too! In Python 2.3, str and unicode have a
1465-
common base class, basestring, so you can do:
1466-
1467-
Okay: if isinstance(obj, basestring):
14681447
"""
14691448
match = COMPARE_TYPE_REGEX.search(logical_line)
14701449
if match and not noqa:
@@ -1787,12 +1766,6 @@ def maximum_doc_length(logical_line, max_doc_length, noqa, tokens):
17871766
if prev_token is None or prev_token in SKIP_TOKENS:
17881767
lines = line.splitlines()
17891768
for line_num, physical_line in enumerate(lines):
1790-
if hasattr(physical_line, 'decode'): # Python 2
1791-
# The line could contain multi-byte characters
1792-
try:
1793-
physical_line = physical_line.decode('utf-8')
1794-
except UnicodeError:
1795-
pass
17961769
if start[0] + line_num == 1 and line.startswith('#!'):
17971770
return
17981771
length = len(physical_line)

testsuite/test_all.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
import pycodestyle
88
from testsuite.support import init_tests, selftest, ROOT_DIR
99

10-
# Note: please only use a subset of unittest methods which were present
11-
# in Python 2.5: assert(True|False|Equal|NotEqual|Raises)
12-
1310

1411
class PycodestyleTestCase(unittest.TestCase):
1512
"""Test the standard errors and warnings (E and W)."""

testsuite/test_api.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -322,29 +322,14 @@ def test_styleguide_check_files(self):
322322
# < 3.3 raises TypeError; >= 3.3 raises AttributeError
323323
self.assertRaises(Exception, pep8style.check_files, [42])
324324

325-
def test_check_unicode(self):
326-
# Do not crash if lines are Unicode (Python 2.x)
327-
pycodestyle.register_check(DummyChecker, ['Z701'])
328-
source = u'#\n'
329-
330-
pep8style = pycodestyle.StyleGuide()
331-
count_errors = pep8style.input_file('stdin', lines=[source])
332-
333-
self.assertFalse(sys.stdout)
334-
self.assertFalse(sys.stderr)
335-
self.assertEqual(count_errors, 0)
336-
337325
def test_check_nullbytes(self):
338326
pycodestyle.register_check(DummyChecker, ['Z701'])
339327

340328
pep8style = pycodestyle.StyleGuide()
341329
count_errors = pep8style.input_file('stdin', lines=['\x00\n'])
342330

343331
stdout = sys.stdout.getvalue()
344-
if 'ValueError' in stdout: # pragma: no cover (python 3.5+)
345-
expected = "stdin:1:1: E901 ValueError"
346-
else: # pragma: no cover (< python3.5)
347-
expected = "stdin:1:1: E901 TypeError"
332+
expected = "stdin:1:1: E901 ValueError"
348333
self.assertTrue(stdout.startswith(expected),
349334
msg='Output %r does not start with %r' %
350335
(stdout, expected))

0 commit comments

Comments
 (0)