From 7e01a1252a846c2b20becb4488cb1bb95f2863d9 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Wed, 21 Sep 2022 19:22:58 +0200 Subject: Allow conditional variants as first values in a variant directive (#32740) --- lib/spack/spack/test/variant.py | 11 +++++++++-- lib/spack/spack/variant.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/test/variant.py b/lib/spack/spack/test/variant.py index 204514b58d..0284c5ea0c 100644 --- a/lib/spack/spack/test/variant.py +++ b/lib/spack/spack/test/variant.py @@ -2,13 +2,12 @@ # Spack Project Developers. See the top-level COPYRIGHT file for details. # # SPDX-License-Identifier: (Apache-2.0 OR MIT) - - import numbers import pytest import spack.error +import spack.variant from spack.variant import ( BoolValuedVariant, DuplicateVariantError, @@ -737,3 +736,11 @@ def test_disjoint_set_fluent_methods(): assert "none" not in d assert "none" not in [x for x in d] assert "none" not in d.feature_values + + +@pytest.mark.regression("32694") +@pytest.mark.parametrize("other", [True, False]) +def test_conditional_value_comparable_to_bool(other): + value = spack.variant.Value("98", when="@1.0") + comparison = value == other + assert comparison is False diff --git a/lib/spack/spack/variant.py b/lib/spack/spack/variant.py index 1f21aad89f..864ea26446 100644 --- a/lib/spack/spack/variant.py +++ b/lib/spack/spack/variant.py @@ -886,7 +886,7 @@ class Value(object): return hash(self.value) def __eq__(self, other): - if isinstance(other, six.string_types): + if isinstance(other, (six.string_types, bool)): return self.value == other return self.value == other.value -- cgit v1.2.3-60-g2f50