Skip to content

Commit

Permalink
enforcing __slots__ usage in __setattr__ for py<3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Miroslav Shubernetskiy committed May 11, 2017
1 parent b734145 commit 07db7c6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pycontext/context.py
Expand Up @@ -155,9 +155,9 @@ def __setattr__(self, key, value):
:param key: the name of the variable
:param value: the variable value
"""
try:
if key in self.__slots__:
super(Context, self).__setattr__(key, value)
except AttributeError:
else:
self.__setitem__(key, value)

def __eq__(self, other):
Expand Down
1 change: 1 addition & 0 deletions tests/test_context.py
Expand Up @@ -265,6 +265,7 @@ def test_attributes(self):
self.context.push({'qwe': 'asd'})
self.assertEqual(self.context.foo, 'bar')
self.assertEqual(self.context.hello, 'world')
self.assertEqual(self.context['hello'], 'world')
self.assertEqual(self.context.qwe, 'asd')

with self.assertRaises(AttributeError):
Expand Down

0 comments on commit 07db7c6

Please sign in to comment.