Skip to content

Commit

Permalink
Merge pull request #2 from dealertrack/attr
Browse files Browse the repository at this point in the history
enforcing __slots__ usage in __setattr__ for py<3 compatibility
  • Loading branch information
miki725 authored May 11, 2017
2 parents b734145 + 2364a3f commit 1d3817e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
1 change: 0 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ History
~~~~~~~~~~~~~~~~~~

* Add attribute support

* Add make watch target

0.1.0 (2017-03-22)
Expand Down
4 changes: 2 additions & 2 deletions pycontext/context.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 1d3817e

Please sign in to comment.