|
10 | 10 | import compileall
|
11 | 11 | import contextlib
|
12 | 12 | import csv
|
13 |
| -import io |
14 | 13 | import logging
|
15 | 14 | import os.path
|
16 | 15 | import re
|
|
25 | 24 | from pip._vendor import pkg_resources
|
26 | 25 | from pip._vendor.distlib.scripts import ScriptMaker
|
27 | 26 | from pip._vendor.distlib.util import get_export_entry
|
28 |
| -from pip._vendor.six import PY3, StringIO |
| 27 | +from pip._vendor.six import StringIO |
29 | 28 |
|
30 | 29 | from pip._internal.exceptions import InstallationError
|
31 | 30 | from pip._internal.locations import get_major_minor_version
|
|
39 | 38 |
|
40 | 39 | if MYPY_CHECK_RUNNING:
|
41 | 40 | from email.message import Message
|
| 41 | + import typing # noqa F401 |
42 | 42 | from typing import (
|
43 | 43 | Dict, List, Optional, Sequence, Tuple, Any,
|
44 | 44 | Iterable, Iterator, Callable, Set,
|
@@ -602,12 +602,13 @@ def _generate_file(path, **kwargs):
|
602 | 602 | lib_dir=lib_dir)
|
603 | 603 | with _generate_file(record_path, **csv_io_kwargs('w')) as record_file:
|
604 | 604 |
|
605 |
| - # For Python 3, we create the file in text mode, hence we |
606 |
| - # cast record_file to io.StringIO |
607 |
| - if PY3: |
608 |
| - record_file = cast(io.StringIO, record_file) |
| 605 | + # The mypy type inference for record_file is different for |
| 606 | + # Python 3 (typing.IO[Any]) and Python 2 (typing.BinaryIO), |
| 607 | + # leading us to explicitly cast to typing.IO[str] as a workaround |
| 608 | + # for bad Python 2 behaviour |
| 609 | + record_file_obj = cast('typing.IO[str]', record_file) |
609 | 610 |
|
610 |
| - writer = csv.writer(record_file) |
| 611 | + writer = csv.writer(record_file_obj) |
611 | 612 | writer.writerows(sorted_outrows(rows)) # sort to simplify testing
|
612 | 613 |
|
613 | 614 |
|
|
0 commit comments