Skip to content

Commit b2e3f2d

Browse files
committed
Add missing MatchSpec equality operator
1 parent 4185322 commit b2e3f2d

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

libmamba/include/mamba/specs/build_number_spec.hpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,9 @@ namespace mamba::specs
124124
*/
125125
[[nodiscard]] auto contains(BuildNumber point) const -> bool;
126126

127-
// TODO(C++20): replace by the `= default` implementation of `operator==`
128-
[[nodiscard]] auto operator==(const BuildNumberSpec& other) const -> bool
129-
{
130-
return m_predicate == other.m_predicate;
131-
}
127+
[[nodiscard]] auto operator==(const BuildNumberSpec& other) const -> bool = default;
132128

133-
[[nodiscard]] auto operator!=(const BuildNumberSpec& other) const -> bool
134-
{
135-
return !(*this == other);
136-
}
129+
[[nodiscard]] auto operator!=(const BuildNumberSpec& other) const -> bool = default;
137130

138131
private:
139132

libmamba/include/mamba/specs/match_spec.hpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "mamba/specs/version_spec.hpp"
2424
#include "mamba/util/flat_set.hpp"
2525
#include "mamba/util/heap_optional.hpp"
26-
#include "mamba/util/tuple_hash.hpp"
2726

2827
namespace mamba::specs
2928
{
@@ -142,22 +141,15 @@ namespace mamba::specs
142141
*/
143142
[[nodiscard]] auto contains_except_channel(const PackageInfo& pkg) const -> bool;
144143

145-
// TODO(C++20): replace by the `= default` implementation of `operator==`
146-
[[nodiscard]] auto operator==(const MatchSpec& other) const -> bool
147-
{
148-
return m_channel == other.m_channel //
149-
&& m_version == other.m_version //
150-
&& m_name == other.m_name //
151-
&& m_build_string == other.m_build_string //
152-
&& m_name_space == other.m_name_space //
153-
&& m_build_number == other.m_build_number //
154-
&& m_extra == other.m_extra;
155-
}
144+
/**
145+
* Naive attribute-wise comparison.
146+
*
147+
* @warning Some complex matchspec could compare to false but actually represent the same
148+
* set of packages. This strong equality is hard to detect.
149+
*/
150+
[[nodiscard]] auto operator==(const MatchSpec& other) const -> bool = default;
156151

157-
[[nodiscard]] auto operator!=(const MatchSpec& other) const -> bool
158-
{
159-
return !(*this == other);
160-
}
152+
[[nodiscard]] auto operator!=(const MatchSpec& other) const -> bool = default;
161153

162154
auto extra_members_hash() const -> std::size_t;
163155

libmambapy/src/libmambapy/bindings/specs.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,8 @@ namespace mambapy
897897
.def("is_simple", &MatchSpec::is_simple)
898898
.def("is_only_package_name", &MatchSpec::is_only_package_name)
899899
.def("conda_build_form", &MatchSpec::conda_build_form)
900+
.def(py::self == py::self)
901+
.def(py::self != py::self)
900902
.def("__str__", &MatchSpec::to_string)
901903
.def("__copy__", &copy<MatchSpec>)
902904
.def("__deepcopy__", &deepcopy<MatchSpec>, py::arg("memo"));

libmambapy/tests/test_specs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,8 @@ def test_MatchSpec():
932932
assert ms.is_file()
933933
assert str(ms.name) == "pkg"
934934
assert ms.filename == "pkg-2-bld.conda"
935+
assert ms == ms
936+
assert ms != MatchSpec.parse("foo")
935937

936938
# Errors
937939
with pytest.raises(libmambapy.specs.ParseError):

0 commit comments

Comments
 (0)