Make classifications singleton#46
Merged
alanocallaghan merged 3 commits intoqupath:mainfrom Oct 22, 2025
Merged
Conversation
Member
|
From the description (I haven’t tried it or studied the code), I like the sound of all this.
Me too. I can’t think of a reason why we’d need it. Can the |
Contributor
Author
|
Yes I have that locally in the office, all it changes is the last assertion here no longer holds |
Rylern
approved these changes
Oct 22, 2025
Contributor
Author
|
There was some discussion about whether we should drop Classification entirely and just use a tuple of names, but I think for now it is better to store the association between class and color in the objects. Merging and I will test more thoroughly in my ongoing work with objects and measurements |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Change the method of caching in Classification to be on instance creation rather than with a separate method; this effectively enforces that sets of class names are unique. Therefore removes the get_cached method.
Adjust the equality test to ignore color and check for instance equality first (although caching in the constructor means that color should always be equal anyway, and values with the same name should still be equivalent).
Use
namestuple directly as cache key.Add some type checking to classification code, but massage the "obvious" inputs: bare str, list and tuple.
Removes
nameentirely, which is a mild inconvenience for getting a single string but should make the code more flexible.I considered moving hidden attributes from single to double underscore to encourage name mangling, but apparently this is "not Pythonic" which makes me feel not very Pythonic
Related to discussions in #45 and #44; resolve #45