diff --git a/changelog.md b/changelog.md index f7f1ab35..d5cabb27 100644 --- a/changelog.md +++ b/changelog.md @@ -5,6 +5,8 @@ > [!IMPORTANT] > This version is not released yet and is under active development. +- Deduplicate platforms on `Group` instantiation. + ## [1.4.0 (2024-10-21)](https://github.com/kdeldycke/extra-platforms/compare/v1.3.1...v1.4.0) - Allow set comparison between groups and single platform. diff --git a/extra_platforms/groups.py b/extra_platforms/groups.py index 528508e0..24651be4 100644 --- a/extra_platforms/groups.py +++ b/extra_platforms/groups.py @@ -96,19 +96,20 @@ class Group: """ def __post_init__(self): - """Keep the platforms sorted by IDs.""" + """Deduplicate platforms and sort them by IDs.""" object.__setattr__( self, "platforms", - tuple(sorted(self.platforms, key=lambda p: p.id)), + tuple(sorted(set(self.platforms), key=lambda p: p.id)), ) object.__setattr__( self, "platform_ids", frozenset({p.id for p in self.platforms}), ) - # Double-check there is no duplicate platforms. - assert len(self.platforms) == len(self.platform_ids) + assert len(self.platforms) == len( + self.platform_ids + ), "The group contain platforms with duplicate IDs" def __iter__(self) -> Iterator[Platform]: """Iterate over the platforms of the group.""" diff --git a/tests/test_groups.py b/tests/test_groups.py index 6af0e77e..e5255960 100644 --- a/tests/test_groups.py +++ b/tests/test_groups.py @@ -86,6 +86,11 @@ from extra_platforms import groups as groups_module +def test_platform_deduplication(): + my_group = Group("my_group", "My Group", "✅", (AIX, AIX)) + assert len(my_group) == 1 + + def test_group_definitions(): for group in ALL_GROUPS: # ID.