|
10 | 10 | import compileall
|
11 | 11 | import contextlib
|
12 | 12 | import csv
|
| 13 | +import io |
13 | 14 | import logging
|
14 | 15 | import os.path
|
15 | 16 | import re
|
|
24 | 25 | from pip._vendor import pkg_resources
|
25 | 26 | from pip._vendor.distlib.scripts import ScriptMaker
|
26 | 27 | from pip._vendor.distlib.util import get_export_entry
|
27 |
| -from pip._vendor.six import StringIO |
| 28 | +from pip._vendor.six import PY3, StringIO |
28 | 29 |
|
29 | 30 | from pip._internal.exceptions import InstallationError
|
30 | 31 | from pip._internal.locations import get_major_minor_version
|
31 | 32 | from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, DirectUrl
|
32 | 33 | from pip._internal.utils.filesystem import adjacent_tmp_file, replace
|
33 | 34 | from pip._internal.utils.misc import captured_stdout, ensure_dir, hash_file
|
34 | 35 | from pip._internal.utils.temp_dir import TempDirectory
|
35 |
| -from pip._internal.utils.typing import MYPY_CHECK_RUNNING |
| 36 | +from pip._internal.utils.typing import MYPY_CHECK_RUNNING, cast |
36 | 37 | from pip._internal.utils.unpacking import current_umask, unpack_file
|
37 | 38 | from pip._internal.utils.wheel import parse_wheel
|
38 | 39 |
|
@@ -600,6 +601,12 @@ def _generate_file(path, **kwargs):
|
600 | 601 | generated=generated,
|
601 | 602 | lib_dir=lib_dir)
|
602 | 603 | with _generate_file(record_path, **csv_io_kwargs('w')) as record_file:
|
| 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) |
| 609 | + |
603 | 610 | writer = csv.writer(record_file)
|
604 | 611 | writer.writerows(sorted_outrows(rows)) # sort to simplify testing
|
605 | 612 |
|
|
0 commit comments