Skip to content

Commit 3f6df16

Browse files
committed
Remove Python 2 compat shim path_to_display()
Per the function's type signature, this accepted either a str or None. In both cases, the value was returned unaltered. Since dropping Python 2, it has been unnecessary.
1 parent 32a2956 commit 3f6df16

File tree

5 files changed

+5
-47
lines changed

5 files changed

+5
-47
lines changed

news/a06e528d-1172-4012-a0a5-0fc42264a70d.trivial.rst

Whitespace-only changes.

src/pip/_internal/operations/prepare.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from pip._internal.utils.filesystem import copy2_fixed
3333
from pip._internal.utils.hashes import MissingHashes
3434
from pip._internal.utils.logging import indent_log
35-
from pip._internal.utils.misc import display_path, hide_url, path_to_display, rmtree
35+
from pip._internal.utils.misc import display_path, hide_url, rmtree
3636
from pip._internal.utils.temp_dir import TempDirectory
3737
from pip._internal.utils.unpacking import unpack_file
3838
from pip._internal.vcs import vcs
@@ -128,8 +128,8 @@ def _copy2_ignoring_special_files(src, dest):
128128
logger.warning(
129129
"Ignoring special file error '%s' encountered copying %s to %s.",
130130
str(e),
131-
path_to_display(src),
132-
path_to_display(dest),
131+
src,
132+
dest,
133133
)
134134

135135

src/pip/_internal/utils/misc.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,6 @@ def rmtree_errorhandler(func, path, exc_info):
147147
raise
148148

149149

150-
def path_to_display(path):
151-
# type: (Optional[str]) -> Optional[str]
152-
"""
153-
Convert a bytes (or text) path to text (unicode in Python 2) for display
154-
and logging purposes.
155-
156-
This function should never error out. Also, this function is mainly needed
157-
for Python 2 since in Python 3 str paths are already text.
158-
"""
159-
if path is None:
160-
return None
161-
if isinstance(path, str):
162-
return path
163-
# Otherwise, path is a bytes object (str in Python 2).
164-
try:
165-
display_path = path.decode(sys.getfilesystemencoding(), 'strict')
166-
except UnicodeDecodeError:
167-
# Include the full bytes to make troubleshooting easier, even though
168-
# it may not be very human readable.
169-
display_path = ascii(path)
170-
171-
return display_path
172-
173-
174150
def display_path(path):
175151
# type: (str) -> str
176152
"""Gives the display value for a given path, making it relative to cwd

src/pip/_internal/utils/subprocess.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from pip._internal.exceptions import InstallationSubprocessError
99
from pip._internal.utils.compat import console_to_str, str_to_display
1010
from pip._internal.utils.logging import subprocess_logger
11-
from pip._internal.utils.misc import HiddenText, path_to_display
11+
from pip._internal.utils.misc import HiddenText
1212

1313
if TYPE_CHECKING:
1414
from typing import Any, Callable, Iterable, List, Mapping, Optional, Union
@@ -82,7 +82,6 @@ def make_subprocess_output_error(
8282
# "UnicodeDecodeError: 'ascii' codec can't decode byte ..." in Python 2
8383
# if either contains a non-ascii character.
8484
command_display = str_to_display(command, desc='command bytes')
85-
cwd_display = path_to_display(cwd)
8685

8786
# We know the joined output value ends in a newline.
8887
output = ''.join(lines)
@@ -97,7 +96,7 @@ def make_subprocess_output_error(
9796
).format(
9897
exit_status=exit_status,
9998
command_display=command_display,
100-
cwd_display=cwd_display,
99+
cwd_display=cwd,
101100
line_count=len(lines),
102101
output=output,
103102
divider=LOG_DIVIDER,

tests/unit/test_utils.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
normalize_path,
3939
normalize_version_info,
4040
parse_netloc,
41-
path_to_display,
4241
redact_auth_from_url,
4342
redact_netloc,
4443
remove_auth_from_url,
@@ -431,22 +430,6 @@ def test_rmtree_retries_for_3sec(tmpdir, monkeypatch):
431430
)
432431

433432

434-
@pytest.mark.parametrize('path, fs_encoding, expected', [
435-
(None, None, None),
436-
# Test passing a text (unicode) string.
437-
('/path/déf', None, '/path/déf'),
438-
# Test a bytes object with a non-ascii character.
439-
('/path/déf'.encode('utf-8'), 'utf-8', '/path/déf'),
440-
# Test a bytes object with a character that can't be decoded.
441-
('/path/déf'.encode('utf-8'), 'ascii', "b'/path/d\\xc3\\xa9f'"),
442-
('/path/déf'.encode('utf-16'), 'utf-8', expected_byte_string),
443-
])
444-
def test_path_to_display(monkeypatch, path, fs_encoding, expected):
445-
monkeypatch.setattr(sys, 'getfilesystemencoding', lambda: fs_encoding)
446-
actual = path_to_display(path)
447-
assert actual == expected, f'actual: {actual!r}'
448-
449-
450433
class Test_normalize_path:
451434
# Technically, symlinks are possible on Windows, but you need a special
452435
# permission bit to create them, and Python 2 doesn't support it anyway, so

0 commit comments

Comments
 (0)