diff --git a/src/packaging/pylock.py b/src/packaging/pylock.py index 1c72fb0df..f06a1fbd5 100644 --- a/src/packaging/pylock.py +++ b/src/packaging/pylock.py @@ -452,7 +452,7 @@ def _from_dict(cls, d: Mapping[str, Any]) -> Self: @property def filename(self) -> str: """Get the filename of the sdist.""" - filename = self.name or _url_name(self.url) or _path_name(self.path) + filename = self.name or _path_name(self.path) or _url_name(self.url) if not filename: raise PylockValidationError("Cannot determine sdist filename") return filename @@ -501,7 +501,7 @@ def _from_dict(cls, d: Mapping[str, Any]) -> Self: @property def filename(self) -> str: """Get the filename of the wheel.""" - filename = self.name or _url_name(self.url) or _path_name(self.path) + filename = self.name or _path_name(self.path) or _url_name(self.url) if not filename: raise PylockValidationError("Cannot determine wheel filename") return filename diff --git a/tests/test_pylock.py b/tests/test_pylock.py index f29b47e5e..f99a82d5c 100644 --- a/tests/test_pylock.py +++ b/tests/test_pylock.py @@ -339,13 +339,13 @@ def test_pylock_invalid_vcs() -> None: "example-2.0.tar.gz", ), ( - # url preferred over path + # path preferred over url PackageSdist( url="https://example.com/example-2.0.tar.gz", path="./example-1.0.tar.gz", hashes={}, ), - "example-2.0.tar.gz", + "example-1.0.tar.gz", ), # wheels ( @@ -402,13 +402,13 @@ def test_pylock_invalid_vcs() -> None: "example-2.0-py3-none-any.whl", ), ( - # url preferred over path + # path preferred over url PackageWheel( url="https://example.com/example-2.0-py3-none-any.whl", path="./example-1.0-py3-none-any.whl", hashes={}, ), - "example-2.0-py3-none-any.whl", + "example-1.0-py3-none-any.whl", ), ], )