Skip to content

Commit

Permalink
Include the f where needed in some f-strings. (#1225)
Browse files Browse the repository at this point in the history
Co-authored-by: William Woodruff <[email protected]>
  • Loading branch information
mbyrnepr2 and woodruffw authored Jan 28, 2025
1 parent aa3a910 commit d9e4b08
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog/1224.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a couple of incorrectly rendered error messages.
10 changes: 8 additions & 2 deletions tests/test_sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ def test_pkg_info_not_regular_file(tmp_path):
},
)

with pytest.raises(exceptions.InvalidDistribution, match="PKG-INFO is not a reg"):
with pytest.raises(
exceptions.InvalidDistribution,
match=r"^PKG-INFO is not a reg.*test-1.2.3.tar.gz$",
):
sdist.SDist(str(filepath)).read()


Expand All @@ -162,7 +165,10 @@ def test_multiple_top_level(archive_format, tmp_path):
},
)

with pytest.raises(exceptions.InvalidDistribution, match="Too many top-level"):
with pytest.raises(
exceptions.InvalidDistribution,
match=r"^Too many top-level.*test-1.2.3.(tar.gz|zip)$",
):
sdist.SDist(str(filepath)).read()


Expand Down
6 changes: 3 additions & 3 deletions twine/sdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ def read(self) -> bytes:
root = os.path.commonpath(sdist.getnames())
if root in {".", "/", ""}:
raise exceptions.InvalidDistribution(
"Too many top-level members in sdist archive: {self.filename}"
f"Too many top-level members in sdist archive: {self.filename}"
)
# ...containing the package metadata in a ``PKG-INFO`` file.
with suppress(KeyError):
member = sdist.getmember(root.rstrip("/") + "/PKG-INFO")
if not member.isfile():
raise exceptions.InvalidDistribution(
"PKG-INFO is not a regular file: {self.filename}"
f"PKG-INFO is not a regular file: {self.filename}"
)
fd = sdist.extractfile(member)
assert fd is not None, "for mypy"
Expand All @@ -69,7 +69,7 @@ def read(self) -> bytes:
root = os.path.commonpath(sdist.namelist())
if root in {".", "/", ""}:
raise exceptions.InvalidDistribution(
"Too many top-level members in sdist archive: {self.filename}"
f"Too many top-level members in sdist archive: {self.filename}"
)
# ...containing the package metadata in a ``PKG-INFO`` file.
with suppress(KeyError):
Expand Down

0 comments on commit d9e4b08

Please sign in to comment.