Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove some leftover python 2 compat #1124

Merged
merged 1 commit into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 4 additions & 8 deletions pycodestyle.py
Expand Up @@ -47,7 +47,9 @@
900 syntax error
"""
import bisect
import configparser
import inspect
import io
import keyword
import os
import re
Expand All @@ -59,12 +61,6 @@
from functools import lru_cache
from optparse import OptionParser

try:
from configparser import RawConfigParser
from io import TextIOWrapper
except ImportError:
from ConfigParser import RawConfigParser

# this is a performance hack. see https://bugs.python.org/issue43014
if (
sys.version_info < (3, 10) and
Expand Down Expand Up @@ -1769,7 +1765,7 @@ def readlines(filename):

def stdin_get_value():
"""Read the value from stdin."""
return TextIOWrapper(sys.stdin.buffer, errors='ignore').read()
return io.TextIOWrapper(sys.stdin.buffer, errors='ignore').read()


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

cli_conf = options.config

Expand Down
7 changes: 4 additions & 3 deletions testsuite/test_shell.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import configparser
import os.path
import sys
import unittest
Expand All @@ -15,7 +16,7 @@ def setUp(self):
self._saved_stdout = sys.stdout
self._saved_stderr = sys.stderr
self._saved_pconfig = pycodestyle.PROJECT_CONFIG
self._saved_cpread = pycodestyle.RawConfigParser._read
self._saved_cpread = configparser.RawConfigParser._read
self._saved_stdin_get_value = pycodestyle.stdin_get_value
self._config_filenames = []
self.stdin = ''
Expand All @@ -25,15 +26,15 @@ def setUp(self):

def fake_config_parser_read(cp, fp, filename):
self._config_filenames.append(filename)
pycodestyle.RawConfigParser._read = fake_config_parser_read
configparser.RawConfigParser._read = fake_config_parser_read
pycodestyle.stdin_get_value = self.stdin_get_value

def tearDown(self):
sys.argv = self._saved_argv
sys.stdout = self._saved_stdout
sys.stderr = self._saved_stderr
pycodestyle.PROJECT_CONFIG = self._saved_pconfig
pycodestyle.RawConfigParser._read = self._saved_cpread
configparser.RawConfigParser._read = self._saved_cpread
pycodestyle.stdin_get_value = self._saved_stdin_get_value

def stdin_get_value(self):
Expand Down