Skip to content

Commit af08f1c

Browse files
authored
Keep _constraint and _pretty_constraint of Dependency synchronized when calling set_constraint() (#214)
1 parent 6215dd1 commit af08f1c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/poetry/core/packages/dependency.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ def __init__(
5656
)
5757

5858
self._constraint = None
59+
self._pretty_constraint = None
5960
self.set_constraint(constraint=constraint)
6061

61-
self._pretty_constraint = str(constraint)
6262
self._optional = optional
6363

6464
if not groups:
@@ -109,6 +109,7 @@ def set_constraint(self, constraint: Union[str, "VersionTypes"]) -> None:
109109
self._constraint = constraint
110110
except ValueError:
111111
self._constraint = parse_constraint("*")
112+
self._pretty_constraint = str(constraint)
112113

113114
@property
114115
def pretty_constraint(self) -> str:

tests/packages/test_dependency.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ def test_dependency_string_representation(
250250
assert str(dependency) == expected
251251

252252

253+
def test_set_constraint_sets_pretty_constraint():
254+
dependency = Dependency("A", "^1.0")
255+
assert dependency.pretty_constraint == "^1.0"
256+
dependency.set_constraint("^2.0")
257+
assert dependency.pretty_constraint == "^2.0"
258+
259+
253260
def test_with_constraint():
254261
dependency = Dependency(
255262
"foo",

0 commit comments

Comments
 (0)