Skip to content

Commit 6c338a8

Browse files
authored
Use !r formatter for error messages with filenames. (#844)
Because I've been tracking an empty filename for some time, and it took me a while to realise it was just here in my logs invisible. So adding !r everywhere, so that at least there is a pair of quotes.
1 parent 28e7da7 commit 6c338a8

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/packaging/utils.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -96,36 +96,36 @@ def parse_wheel_filename(
9696
) -> tuple[NormalizedName, Version, BuildTag, frozenset[Tag]]:
9797
if not filename.endswith(".whl"):
9898
raise InvalidWheelFilename(
99-
f"Invalid wheel filename (extension must be '.whl'): {filename}"
99+
f"Invalid wheel filename (extension must be '.whl'): {filename!r}"
100100
)
101101

102102
filename = filename[:-4]
103103
dashes = filename.count("-")
104104
if dashes not in (4, 5):
105105
raise InvalidWheelFilename(
106-
f"Invalid wheel filename (wrong number of parts): {filename}"
106+
f"Invalid wheel filename (wrong number of parts): {filename!r}"
107107
)
108108

109109
parts = filename.split("-", dashes - 2)
110110
name_part = parts[0]
111111
# See PEP 427 for the rules on escaping the project name.
112112
if "__" in name_part or re.match(r"^[\w\d._]*$", name_part, re.UNICODE) is None:
113-
raise InvalidWheelFilename(f"Invalid project name: {filename}")
113+
raise InvalidWheelFilename(f"Invalid project name: {filename!r}")
114114
name = canonicalize_name(name_part)
115115

116116
try:
117117
version = Version(parts[1])
118118
except InvalidVersion as e:
119119
raise InvalidWheelFilename(
120-
f"Invalid wheel filename (invalid version): {filename}"
120+
f"Invalid wheel filename (invalid version): {filename!r}"
121121
) from e
122122

123123
if dashes == 5:
124124
build_part = parts[2]
125125
build_match = _build_tag_regex.match(build_part)
126126
if build_match is None:
127127
raise InvalidWheelFilename(
128-
f"Invalid build number: {build_part} in '{filename}'"
128+
f"Invalid build number: {build_part} in '{filename!r}'"
129129
)
130130
build = cast(BuildTag, (int(build_match.group(1)), build_match.group(2)))
131131
else:
@@ -142,22 +142,22 @@ def parse_sdist_filename(filename: str) -> tuple[NormalizedName, Version]:
142142
else:
143143
raise InvalidSdistFilename(
144144
f"Invalid sdist filename (extension must be '.tar.gz' or '.zip'):"
145-
f" {filename}"
145+
f" {filename!r}"
146146
)
147147

148148
# We are requiring a PEP 440 version, which cannot contain dashes,
149149
# so we split on the last dash.
150150
name_part, sep, version_part = file_stem.rpartition("-")
151151
if not sep:
152-
raise InvalidSdistFilename(f"Invalid sdist filename: {filename}")
152+
raise InvalidSdistFilename(f"Invalid sdist filename: {filename!r}")
153153

154154
name = canonicalize_name(name_part)
155155

156156
try:
157157
version = Version(version_part)
158158
except InvalidVersion as e:
159159
raise InvalidSdistFilename(
160-
f"Invalid sdist filename (invalid version): {filename}"
160+
f"Invalid sdist filename (invalid version): {filename!r}"
161161
) from e
162162

163163
return (name, version)

0 commit comments

Comments
 (0)