Skip to content

Commit 956ab1f

Browse files
committed
remove some leftover python 2 compat
1 parent c5308a7 commit 956ab1f

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

pycodestyle.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
900 syntax error
4848
"""
4949
import bisect
50+
import configparser
5051
import inspect
52+
import io
5153
import keyword
5254
import os
5355
import re
@@ -59,12 +61,6 @@
5961
from functools import lru_cache
6062
from optparse import OptionParser
6163

62-
try:
63-
from configparser import RawConfigParser
64-
from io import TextIOWrapper
65-
except ImportError:
66-
from ConfigParser import RawConfigParser
67-
6864
# this is a performance hack. see https://bugs.python.org/issue43014
6965
if (
7066
sys.version_info < (3, 10) and
@@ -1769,7 +1765,7 @@ def readlines(filename):
17691765

17701766
def stdin_get_value():
17711767
"""Read the value from stdin."""
1772-
return TextIOWrapper(sys.stdin.buffer, errors='ignore').read()
1768+
return io.TextIOWrapper(sys.stdin.buffer, errors='ignore').read()
17731769

17741770

17751771
noqa = lru_cache(512)(re.compile(r'# no(?:qa|pep8)\b', re.I).search)
@@ -2558,7 +2554,7 @@ def read_config(options, args, arglist, parser):
25582554
merged together (in that order) using the read method of
25592555
ConfigParser.
25602556
"""
2561-
config = RawConfigParser()
2557+
config = configparser.RawConfigParser()
25622558

25632559
cli_conf = options.config
25642560

testsuite/test_shell.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
import configparser
23
import os.path
34
import sys
45
import unittest
@@ -15,7 +16,7 @@ def setUp(self):
1516
self._saved_stdout = sys.stdout
1617
self._saved_stderr = sys.stderr
1718
self._saved_pconfig = pycodestyle.PROJECT_CONFIG
18-
self._saved_cpread = pycodestyle.RawConfigParser._read
19+
self._saved_cpread = configparser.RawConfigParser._read
1920
self._saved_stdin_get_value = pycodestyle.stdin_get_value
2021
self._config_filenames = []
2122
self.stdin = ''
@@ -25,15 +26,15 @@ def setUp(self):
2526

2627
def fake_config_parser_read(cp, fp, filename):
2728
self._config_filenames.append(filename)
28-
pycodestyle.RawConfigParser._read = fake_config_parser_read
29+
configparser.RawConfigParser._read = fake_config_parser_read
2930
pycodestyle.stdin_get_value = self.stdin_get_value
3031

3132
def tearDown(self):
3233
sys.argv = self._saved_argv
3334
sys.stdout = self._saved_stdout
3435
sys.stderr = self._saved_stderr
3536
pycodestyle.PROJECT_CONFIG = self._saved_pconfig
36-
pycodestyle.RawConfigParser._read = self._saved_cpread
37+
configparser.RawConfigParser._read = self._saved_cpread
3738
pycodestyle.stdin_get_value = self._saved_stdin_get_value
3839

3940
def stdin_get_value(self):

0 commit comments

Comments
 (0)