From 65f8f9277c1576775d1d6d108764ef0db0961ea2 Mon Sep 17 00:00:00 2001 From: Alexis ANNEIX Date: Thu, 18 Sep 2025 16:46:54 +0200 Subject: [PATCH 1/3] Make ArchFXVariableID hashable and usable in a mapping as a key By overriding the `__hash__()` method mainly. I've also overridden the `__eq__()` method to be sure we are consistent, considering that 2 ArchFXVariableID with the same slug are actually equal (instead of comparing the instance themselves). --- archfx_cloud/utils/slugs.py | 10 +++++++++- tests/test_slugs.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/archfx_cloud/utils/slugs.py b/archfx_cloud/utils/slugs.py index 7cad4fd..357b38f 100644 --- a/archfx_cloud/utils/slugs.py +++ b/archfx_cloud/utils/slugs.py @@ -36,7 +36,15 @@ class ArchFxCloudSlug(object): _slug = None def __str__(self): - return self._slug + return self._slug or '' + + def __hash__(self): + return hash(self._slug) + + def __eq__(self, other): + if isinstance(other, ArchFxCloudSlug): + return self._slug == other._slug + return super().__eq__(other) def formatted_id(self): parts = gid_split(self._slug) diff --git a/tests/test_slugs.py b/tests/test_slugs.py index 1bae9db..b2b26b2 100644 --- a/tests/test_slugs.py +++ b/tests/test_slugs.py @@ -33,6 +33,21 @@ def test_ArchFxVariableID(name, input, formatted, scope, var): assert result.scope == scope assert result.scope_hex == f"{scope:04x}" + other = ArchFxVariableID(input) + assert str(result) == str(other) + assert hash(result) == hash(other) + assert result == other + + other2 = ArchFxVariableID('9999-9999') + assert str(result) != str(other2) + assert hash(result) != hash(other2) + assert result != other2 + + mapping = {result: 'value'} + assert mapping[result] == 'value' + assert mapping[other] == 'value' + assert mapping.get(other2) is None + class SlugTestCase(unittest.TestCase): From 322cabdd74eb8852fb34d449973d7c8cb2d577fb Mon Sep 17 00:00:00 2001 From: Alexis ANNEIX Date: Thu, 18 Sep 2025 17:24:09 +0200 Subject: [PATCH 2/3] Update release note --- RELEASE.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RELEASE.md b/RELEASE.md index b73159f..1dd0e6b 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -2,6 +2,11 @@ All major changes in each released version of the archfx-cloud plugin are listed here. +## 0.17.0 + +- Made `ArchFxCloudSlug` (and all its derived classes) usable as a mapping key by overriding the `__hash__()` method. +- Made `ArchFxCloudSlug` (and all its derived classes) considered equal if their `slug` attributes are equal by overriding the `__eq__()` method. + ## 0.16.0 - Updated `dev` domain in `BaseMain` class to be `http://localhost`. From 48444f619203717879bcc845ba1a8ac4ab7d014c Mon Sep 17 00:00:00 2001 From: Alexis ANNEIX Date: Thu, 18 Sep 2025 17:50:47 +0200 Subject: [PATCH 3/3] Update version.py to 0.17.0 --- version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.py b/version.py index 6e61e44..0631519 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -version = '0.16.0' +version = '0.17.0'