Skip to content

Commit

Permalink
dependency: allow constraint to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
abn committed Sep 30, 2020
1 parent 59bd2ce commit 8393d12
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions poetry/core/packages/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,8 @@ def __init__(
features=extras,
)

try:
if not isinstance(constraint, VersionConstraint):
self._constraint = parse_constraint(constraint)
else:
self._constraint = constraint
except ValueError:
self._constraint = parse_constraint("*")
self._constraint = None
self.set_constraint(constraint=constraint)

self._pretty_constraint = str(constraint)
self._optional = optional
Expand Down Expand Up @@ -86,6 +81,15 @@ def name(self):
def constraint(self):
return self._constraint

def set_constraint(self, constraint):
try:
if not isinstance(constraint, VersionConstraint):
self._constraint = parse_constraint(constraint)
else:
self._constraint = constraint
except ValueError:
self._constraint = parse_constraint("*")

@property
def pretty_constraint(self):
return self._pretty_constraint
Expand Down

0 comments on commit 8393d12

Please sign in to comment.