|
32 | 32 | from pip._internal.utils.filesystem import adjacent_tmp_file, replace
|
33 | 33 | from pip._internal.utils.misc import captured_stdout, ensure_dir, hash_file
|
34 | 34 | from pip._internal.utils.temp_dir import TempDirectory
|
35 |
| -from pip._internal.utils.typing import MYPY_CHECK_RUNNING |
| 35 | +from pip._internal.utils.typing import MYPY_CHECK_RUNNING, cast |
36 | 36 | from pip._internal.utils.unpacking import current_umask, unpack_file
|
37 | 37 | from pip._internal.utils.wheel import parse_wheel
|
38 | 38 |
|
39 | 39 | if MYPY_CHECK_RUNNING:
|
40 | 40 | from email.message import Message
|
| 41 | + import typing # noqa F401 |
41 | 42 | from typing import (
|
42 | 43 | Dict, List, Optional, Sequence, Tuple, Any,
|
43 | 44 | Iterable, Iterator, Callable, Set,
|
@@ -600,7 +601,15 @@ 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:
|
603 |
| - writer = csv.writer(record_file) |
| 604 | + |
| 605 | + # The type mypy infers for record_file using reveal_type |
| 606 | + # is different for Python 3 (typing.IO[Any]) and |
| 607 | + # Python 2 (typing.BinaryIO), leading us to explicitly |
| 608 | + # cast to typing.IO[str] as a workaround |
| 609 | + # for bad Python 2 behaviour |
| 610 | + record_file_obj = cast('typing.IO[str]', record_file) |
| 611 | + |
| 612 | + writer = csv.writer(record_file_obj) |
604 | 613 | writer.writerows(sorted_outrows(rows)) # sort to simplify testing
|
605 | 614 |
|
606 | 615 |
|
|
0 commit comments