Skip to content

Add less than comparison method for Addon class#326

Merged
chennes merged 1 commit intoFreeCAD:devfrom
chennes:addLessThan
Jan 22, 2026
Merged

Add less than comparison method for Addon class#326
chennes merged 1 commit intoFreeCAD:devfrom
chennes:addLessThan

Conversation

@chennes
Copy link
Member

@chennes chennes commented Jan 22, 2026

No description provided.

Copilot AI review requested due to automatic review settings January 22, 2026 19:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a __lt__ (less than) comparison method to the Addon class, enabling sorting and comparison operations on Addon instances. The sorting is performed first by the addon's name, and then by branch_display_name as a tiebreaker for addons with the same name.

Changes:

  • Added __lt__ method to enable sorting of Addon instances by name and branch_display_name
Comments suppressed due to low confidence (1)

Addon.py:83

  • This class implements lt, but does not implement le or ge.
class Addon:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +234 to +239
def __lt__(self, other):
if not isinstance(other, Addon):
return NotImplemented
if self.name == other.name:
return self.branch_display_name < other.branch_display_name
return self.name < other.name
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new __lt__ method lacks test coverage. Since this method enables sorting behavior that is used in the codebase (for example, external_addons.sort() in the MissingDependencies class), it would be beneficial to add tests that verify the sorting behavior works correctly for different scenarios such as addons with the same name but different branches, and addons with different names.

Copilot uses AI. Check for mistakes.
self.assertLess(aa, ab)

same = Addon("A", branch="A")
self.assertFalse(same < aa)

Check notice

Code scanning / CodeQL

Imprecise assert

assertFalse(a < b) cannot provide an informative message. Using assertGreaterEqual(a, b) instead will give more informative messages.

same = Addon("A", branch="A")
self.assertFalse(same < aa)
self.assertFalse(aa < same)

Check notice

Code scanning / CodeQL

Imprecise assert

assertFalse(a < b) cannot provide an informative message. Using assertGreaterEqual(a, b) instead will give more informative messages.
def test_addon_less_than_or_equal_to(self):
a = Addon("A")
b = Addon("B")
self.assertTrue(a <= b)

Check notice

Code scanning / CodeQL

Imprecise assert

assertTrue(a <= b) cannot provide an informative message. Using assertLessEqual(a, b) instead will give more informative messages.

aa = Addon("A", branch="A")
ab = Addon("A", branch="B")
self.assertTrue(aa <= ab)

Check notice

Code scanning / CodeQL

Imprecise assert

assertTrue(a <= b) cannot provide an informative message. Using assertLessEqual(a, b) instead will give more informative messages.
self.assertTrue(aa <= ab)

same = Addon("A", branch="A")
self.assertTrue(same <= aa)

Check notice

Code scanning / CodeQL

Imprecise assert

assertTrue(a <= b) cannot provide an informative message. Using assertLessEqual(a, b) instead will give more informative messages.

same = Addon("A", branch="A")
self.assertTrue(same <= aa)
self.assertTrue(aa <= same)

Check notice

Code scanning / CodeQL

Imprecise assert

assertTrue(a <= b) cannot provide an informative message. Using assertLessEqual(a, b) instead will give more informative messages.
self.assertLessEqual(aa, ab)

same = Addon("A", branch="A")
self.assertLessEqual(same, aa)

Check notice

Code scanning / CodeQL

Imprecise assert Note test

assertTrue(a <= b) cannot provide an informative message. Using assertLessEqual(a, b) instead will give more informative messages.

same = Addon("A", branch="A")
self.assertLessEqual(same, aa)
self.assertLessEqual(aa, same)

Check notice

Code scanning / CodeQL

Imprecise assert Note test

assertTrue(a <= b) cannot provide an informative message. Using assertLessEqual(a, b) instead will give more informative messages.
@chennes chennes merged commit 01e242e into FreeCAD:dev Jan 22, 2026
11 checks passed
@chennes chennes added the release to main Trigger an Action to create a PR backporting to `main` label Jan 22, 2026
@github-actions
Copy link

Successfully created backport PR for main:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release to main Trigger an Action to create a PR backporting to `main`

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant