ancient-vegetable-10556
08/16/2021, 5:23 PMInterpreterConstraints
with respect to how it orders inputs. Can someone help me understand what the correct behaviour should be here? (test case will appear in thread)ancient-vegetable-10556
08/16/2021, 5:23 PMdef test_ic_ordering():
inputs = ["CPython==2.7.*", "PyPy", "CPython>=3.6,<4,!=3.7.*"]
a = InterpreterConstraints(inputs)
a_str = [str(i) for i in a]
b = InterpreterConstraints(a_str)
print(inputs)
print(a)
print(a_str)
print(b)
assert a == b
which gives the following output:
['CPython==2.7.*', 'PyPy', 'CPython>=3.6,<4,!=3.7.*']
CPython==2.7.* OR CPython!=3.7.*,<4,>=3.6 OR PyPy
['CPython==2.7.*', 'CPython!=3.7.*,<4,>=3.6', 'PyPy']
CPython!=3.7.*,<4,>=3.6 OR CPython==2.7.* OR PyPy
ancient-vegetable-10556
08/16/2021, 5:25 PMhundreds-father-404
08/16/2021, 5:25 PMa != b
, right? Weird. It should be sorting the inputsancient-vegetable-10556
08/16/2021, 5:26 PMsuper().__init__(
v if isinstance(v, Requirement) else self.parse_constraint(v)
for v in sorted(constraints, key=lambda c: str(c))
)
I think the correct behaviour is to convert the list into Requirement
objects, and then do the sort, rather than sorting on the heterogeneous constraintshundreds-father-404
08/16/2021, 5:26 PMancient-vegetable-10556
08/16/2021, 5:27 PMancient-vegetable-10556
08/16/2021, 5:38 PME '!=3.6.1,>=3.6 || ==2.7.*' '==2.7.* || !=3.6.1,>=3.6'
ancient-vegetable-10556
08/16/2021, 5:41 PMparse_requirement
has its own internal ordering problem, which is what caused the parent issue)hundreds-father-404
08/16/2021, 5:43 PMancient-vegetable-10556
08/16/2021, 5:44 PMancient-vegetable-10556
08/16/2021, 5:47 PMRequirement.parse
— so if you input a list[str]
, you’d sort the list before sorting the requirements inside the list, which would mean that initial list came out slightly unsorted. Wheee