diff --git a/src/manage/installs.py b/src/manage/installs.py index c9a1be6..c556b99 100644 --- a/src/manage/installs.py +++ b/src/manage/installs.py @@ -155,7 +155,10 @@ def get_matching_install_tags( exact_matches.append((i, t)) matched_any = True elif not tag or tag.satisfied_by(ct): - if tag and not companies_match(tag.company, i["company"]): + if ( + isinstance(tag, CompanyTag) + and not companies_match(tag.company, i["company"]) + ): fallback_matches.append((i, t)) matched_any = True elif i.get("unmanaged"): diff --git a/src/manage/tagutils.py b/src/manage/tagutils.py index a94dbd3..8ea2cdf 100644 --- a/src/manage/tagutils.py +++ b/src/manage/tagutils.py @@ -219,7 +219,7 @@ def __hash__(self): return hash(self._sortkey) def __eq__(self, other): - if other is None: + if not isinstance(other, type(self)): return False if self._company != other._company: return False @@ -232,6 +232,8 @@ def __eq__(self, other): def __gt__(self, other): if other is None: return True + if not isinstance(other, type(self)): + return False if self._company != other._company: return self._company > other._company if self._sortkey != other._sortkey: @@ -243,6 +245,8 @@ def __gt__(self, other): def matches_bound(self, other): if other is None: return True + if not isinstance(other, type(self)): + return False if not self._company.startswith(other._company): return False if other.platform not in (self.platform, ""): @@ -260,6 +264,8 @@ def matches_bound(self, other): def above_lower_bound(self, other): if other is None: return True + if not isinstance(other, type(self)): + return False if not self._company.startswith(other._company): return False if other.platform not in (self.platform, ""): @@ -275,7 +281,7 @@ def above_lower_bound(self, other): return True def __lt__(self, other): - if other is None: + if not isinstance(other, type(self)): return False if self._company != other._company: return self._company < other._company @@ -288,6 +294,8 @@ def __lt__(self, other): def below_upper_bound(self, other): if other is None: return True + if not isinstance(other, type(self)): + return False if not self._company.startswith(other._company): return False if other.platform not in (self.platform, ""): diff --git a/tests/test_installs.py b/tests/test_installs.py index f16d7e8..0b809ae 100644 --- a/tests/test_installs.py +++ b/tests/test_installs.py @@ -147,6 +147,7 @@ def test_get_install_to_run_with_default_platform(patched_installs): assert i["id"] == "PythonCore-2.0-64" assert i["executable"].match("python.exe") + def test_get_install_to_run_with_default_platform_prerelease(patched_installs2): # Specifically testing issue #25, where a native prerelease is preferred # over a non-native stable release. We should prefer the stable release @@ -158,3 +159,12 @@ def test_get_install_to_run_with_default_platform_prerelease(patched_installs2): assert i["id"] == "PythonCore-1.0-32" i = installs.get_install_to_run("", None, None, default_platform="-arm64") assert i["id"] == "PythonCore-1.0-32" + + +def test_get_install_to_run_with_range(patched_installs): + i = installs.get_install_to_run("", None, "<=1.0") + assert i["id"] == "PythonCore-1.0" + assert i["executable"].match("python.exe") + i = installs.get_install_to_run("", None, ">1.0") + assert i["id"] == "PythonCore-2.0-64" + assert i["executable"].match("python.exe")