packaging icon indicating copy to clipboard operation
packaging copied to clipboard

SpecifierSets that contains arbitrary equality but two different versions evaluates as equal

Open notatallshaw opened this issue 1 year ago • 0 comments

As discussed previously (https://github.com/pypa/packaging/issues/762), I am working on an exhaustive set of tests against the boundry conditions of SpecifierSet.

I would make the assumption that the following would always be true:

version1 = {valid_version1}
version2 = {valid_version2}
operator = {valid_operator}

specifier1 =  SpecifierSet(f'{operator}{valid_version1}')
specifier2 =  SpecifierSet(f'{operator}{valid_version2}')

if (
    specifier1.contains(version1) != specifier2.contains(version1)
    or specifier1.contains(version2) != specifier2.contains(version2)
):
    assert specifier1 != specifier2

However this does now pass for "1", "1.0", and "===":

>>> SpecifierSet('===1').contains("1") 
True
>>> SpecifierSet('===1.0').contains("1") 
False

>>> SpecifierSet('===1').contains("1.0") 
False
>>> SpecifierSet('===1.0').contains("1.0") 
True

>>> SpecifierSet('===1.0') == SpecifierSet('===1')
True

Is this a bug or expected behavior?

notatallshaw avatar Jan 07 '24 12:01 notatallshaw