clean up readlines_py2

This commit is contained in:
Anthony Sottile 2021-03-29 18:13:11 -07:00
parent 3a85c8ce96
commit 4d57a20ffd

View file

@ -3,7 +3,6 @@ import argparse
import ast import ast
import contextlib import contextlib
import logging import logging
import sys
import tokenize import tokenize
from typing import Any from typing import Any
from typing import Dict from typing import Dict
@ -352,13 +351,9 @@ class FileProcessor:
lines = self.read_lines_from_filename() lines = self.read_lines_from_filename()
return lines return lines
def _readlines_py2(self): def read_lines_from_filename(self):
# type: () -> List[str]
with open(self.filename) as fd:
return fd.readlines()
def _readlines_py3(self):
# type: () -> List[str] # type: () -> List[str]
"""Read the lines for a file."""
try: try:
with tokenize.open(self.filename) as fd: with tokenize.open(self.filename) as fd:
return fd.readlines() return fd.readlines()
@ -368,15 +363,6 @@ class FileProcessor:
with open(self.filename, encoding="latin-1") as fd: with open(self.filename, encoding="latin-1") as fd:
return fd.readlines() return fd.readlines()
def read_lines_from_filename(self):
# type: () -> List[str]
"""Read the lines for a file."""
if (2, 6) <= sys.version_info < (3, 0):
readlines = self._readlines_py2
elif (3, 0) <= sys.version_info < (4, 0):
readlines = self._readlines_py3
return readlines()
def read_lines_from_stdin(self): def read_lines_from_stdin(self):
# type: () -> List[str] # type: () -> List[str]
"""Read the lines from standard in.""" """Read the lines from standard in."""