Skip to content

Commit da3e2ed

Browse files
committed
Resolve CI fails
converters are executed before __attrs_post_init__ thus we need to convert explicitly in __attrs_post_init__ See: https://www.attrs.org/en/stable/init.html#order-of-execution Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
1 parent 6d47bdf commit da3e2ed

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

src/univers/version_range.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,13 @@ class VersionRange:
4040

4141
# A list of lists of VersionConstraint that are signposts on the versions
4242
# timeline
43-
constraints = attr.ib(type=tuple, converter=tuple, default=attr.Factory(tuple))
43+
constraints = attr.ib(type=tuple, default=attr.Factory(tuple))
4444

4545
def __attrs_post_init__(self, *args, **kwargs):
46-
self.constraints.sort()
46+
constraints = tuple(sorted(self.constraints))
47+
# Notes: setattr is used because this is an immutable frozen instance.
48+
# See https://www.attrs.org/en/stable/init.html?#post-init
49+
object.__setattr__(self, "constraints", constraints)
4750

4851
@classmethod
4952
def from_native(cls, string):

tests/test_version_range.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ def test_VersionRange_from_string_pypi(self):
4141
version_range = VersionRange.from_string(vers)
4242
assert version_range.scheme == "pypi"
4343
# note the sorting taking place
44-
expected = [
44+
expected = (
4545
VersionConstraint(comparator="=", version=PypiVersion(string="0.0.0")),
4646
VersionConstraint(comparator="=", version=PypiVersion(string="0.0.1")),
4747
VersionConstraint(comparator="=", version=PypiVersion(string="0.0.2")),
4848
VersionConstraint(comparator="=", version=PypiVersion(string="0.0.3")),
4949
VersionConstraint(comparator="=", version=PypiVersion(string="0.0.4")),
5050
VersionConstraint(comparator="=", version=PypiVersion(string="0.0.5")),
5151
VersionConstraint(comparator="=", version=PypiVersion(string="0.0.6")),
52-
]
52+
)
5353
assert version_range.constraints == expected
5454
# note the sorting taking place
5555
assert str(version_range) == "vers:pypi/0.0.0|0.0.1|0.0.2|0.0.3|0.0.4|0.0.5|0.0.6"
@@ -146,7 +146,7 @@ def test_GemVersionRange_from_native_range_with_pessimistic_operator(self):
146146
gem_range = "~>2.0.8"
147147
version_range = GemVersionRange.from_native(gem_range)
148148
assert version_range.to_string() == "vers:gem/>=2.0.8|<2.1"
149-
assert version_range.constraints == [
149+
assert version_range.constraints == )
150150
VersionConstraint(comparator=">=", version=RubygemsVersion(string="2.0.8")),
151151
VersionConstraint(comparator="<", version=RubygemsVersion(string="2.1")),
152-
]
152+
)

0 commit comments

Comments
 (0)