Merged
Conversation
this allows testing of color block sorting algorithms with CPython
Member
|
Looks good to me. I wonder if we should go ahead and implement the Also, since color objects are immutable, we should implement |
Contributor
Author
|
I will have a look at the other methods. |
dlech
reviewed
Apr 25, 2026
Comment on lines
+115
to
+121
| def __setattr__(self, key, value): | ||
| if key not in ("h", "s", "v"): | ||
| raise AttributeError("Can't modify unknown attribute: " + key) | ||
| if hasattr(self, key): # immutable after __init__ | ||
| raise AttributeError("Can't modify immutable attribute: " + key) | ||
| super().__setattr__(key, value) | ||
|
|
Member
There was a problem hiding this comment.
Suggested change
| def __setattr__(self, key, value): | |
| if key not in ("h", "s", "v"): | |
| raise AttributeError("Can't modify unknown attribute: " + key) | |
| if hasattr(self, key): # immutable after __init__ | |
| raise AttributeError("Can't modify immutable attribute: " + key) | |
| super().__setattr__(key, value) | |
| __slots__ = [] | |
This would be simpler and should have about the same effect.
Contributor
Author
There was a problem hiding this comment.
with __slots__ = [] also the assignment in __init__ is blocked.
https://stackoverflow.com/questions/4828080/how-to-make-an-immutable-object-in-python lists various variants. I tried a minimal invasive variant.
Member
|
Thanks! |
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.
this allows testing of color block sorting algorithms with CPython