Skip to content

Commit

Permalink
Keep _constraint and _pretty_constraint of Dependency synchronized wh…
Browse files Browse the repository at this point in the history
…en calling set_constraint() (#214)
  • Loading branch information
radoering authored Nov 21, 2021
1 parent 6215dd1 commit af08f1c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def __init__(
)

self._constraint = None
self._pretty_constraint = None
self.set_constraint(constraint=constraint)

self._pretty_constraint = str(constraint)
self._optional = optional

if not groups:
Expand Down Expand Up @@ -109,6 +109,7 @@ def set_constraint(self, constraint: Union[str, "VersionTypes"]) -> None:
self._constraint = constraint
except ValueError:
self._constraint = parse_constraint("*")
self._pretty_constraint = str(constraint)

@property
def pretty_constraint(self) -> str:
Expand Down
7 changes: 7 additions & 0 deletions tests/packages/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ def test_dependency_string_representation(
assert str(dependency) == expected


def test_set_constraint_sets_pretty_constraint():
dependency = Dependency("A", "^1.0")
assert dependency.pretty_constraint == "^1.0"
dependency.set_constraint("^2.0")
assert dependency.pretty_constraint == "^2.0"


def test_with_constraint():
dependency = Dependency(
"foo",
Expand Down

0 comments on commit af08f1c

Please sign in to comment.