Skip to content

Commit 48eef6f

Browse files
committed
fixed immutability
1 parent 27bd1d1 commit 48eef6f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/pybricks/parameters.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ def __init__(self, h: Number, s: Number = 100, v: Number = 100):
113113
"""
114114

115115
def __setattr__(self, key, value):
116-
if not hasattr(self, key):
117-
super().__setattr__(key, value)
118-
else: # immutable after __init__
119-
raise AttributeError("Can't modify immutable object attribute: " + key)
116+
if key not in ("h", "s", "v"):
117+
raise AttributeError("Can't modify unknown attribute: " + key)
118+
if hasattr(self, key): # immutable after __init__
119+
raise AttributeError("Can't modify immutable attribute: " + key)
120+
super().__setattr__(key, value)
120121

121122
def __iter__(self):
122123
"""Allows unpacking of the Color instance into h, s, and v."""

0 commit comments

Comments
 (0)