Skip to content

Commit

Permalink
🥅✅ Type error for setitem
Browse files Browse the repository at this point in the history
Signed-off-by: Evaline Ju <[email protected]>
  • Loading branch information
evaline-ju committed Apr 25, 2023
1 parent 01a1811 commit b0af872
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aconfig/aconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def __init__(self, input_map, *_):
super().__init__(input_map)

def __setitem__(self, key, value):
raise AttributeError("ImmutableAttributeAccessDict does not support attribute assignment")
raise TypeError("ImmutableAttributeAccessDict does not support item assignment")

def __setattr__(self, key, value):
raise AttributeError("ImmutableAttributeAccessDict does not support attribute assignment")
Expand Down
13 changes: 11 additions & 2 deletions test/test_attribute_access_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def test_immutable_flat_access_dict(self):
flat_dict = aconfig.ImmutableAttributeAccessDict(fixtures.GOOD_FLAT_DICT)
self.assertIsInstance(flat_dict, aconfig.AttributeAccessDict)

with self.assertRaises(AttributeError):
with self.assertRaises(TypeError):
flat_dict['str_key'] = 'new_key'

def test_immutable_nested_access_dict(self):
Expand All @@ -229,5 +229,14 @@ def test_immutable_nested_access_dict(self):
flat_dict = aconfig.ImmutableAttributeAccessDict(fixtures.GOOD_NESTED_DICT)
self.assertIsInstance(flat_dict, aconfig.AttributeAccessDict)

with self.assertRaises(AttributeError):
with self.assertRaises(TypeError):
flat_dict['key2']['key4'] = 'new_key'

def test_immutable_dict_attr(self):
'''Test that immutable dict cannot be changed via attribute
'''
flat_dict = aconfig.ImmutableAttributeAccessDict(fixtures.GOOD_FLAT_DICT)
self.assertIsInstance(flat_dict, aconfig.AttributeAccessDict)

with self.assertRaises(AttributeError):
flat_dict.str_key = 'new_key'

0 comments on commit b0af872

Please sign in to comment.