Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not consider constraints when checking for equality of direct origi… #405

Merged
merged 2 commits into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,14 @@ def __eq__(self, other: object) -> bool:
if not isinstance(other, Dependency):
return NotImplemented

return super().__eq__(other) and self._constraint == other.constraint
# "constraint" is implicitly given for direct origin dependencies and might not
# be set yet ("*"). Thus, it shouldn't be used to determine if two direct origin
# dependencies are equal.
# Calling is_direct_origin() for one dependency is sufficient because
# super().__eq__() returns False for different origins.
return super().__eq__(other) and (
self._constraint == other.constraint or self.is_direct_origin()
)

def __hash__(self) -> int:
# don't include _constraint in hash because it is mutable!
Expand Down
28 changes: 28 additions & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,34 @@ def test_create_from_pep_508_url_with_activated_extras() -> None:
assert dependency.extras == {"fred", "bar"}


@pytest.mark.parametrize(
"dependency1, dependency2, expected",
[
(Dependency("a", "1.0"), Dependency("a", "1.0"), True),
(Dependency("a", "1.0"), Dependency("a", "1.0.1"), False),
(Dependency("a", "1.0"), Dependency("a1", "1.0"), False),
(Dependency("a", "1.0"), Dependency("a", "1.0", source_type="file"), False),
# constraint is implicitly given for direct origin dependencies,
# but might not be set
(
Dependency("a", "1.0", source_type="file"),
Dependency("a", "*", source_type="file"),
True,
),
# constraint is not implicit for non direct origin dependencies
(Dependency("a", "1.0"), Dependency("a", "*"), False),
(
Dependency("a", "1.0", source_type="legacy"),
Dependency("a", "*", source_type="legacy"),
False,
),
],
)
def test_eq(dependency1: Dependency, dependency2: Dependency, expected: bool) -> None:
assert (dependency1 == dependency2) is expected
assert (dependency2 == dependency1) is expected


@pytest.mark.parametrize(
"attr_name, value",
[
Expand Down