From 07db7c61a24e81d4ab23c7a284926e78e1542e79 Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 11 May 2017 11:01:04 -0400 Subject: [PATCH 1/2] enforcing __slots__ usage in __setattr__ for py<3 compatibility --- pycontext/context.py | 4 ++-- tests/test_context.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pycontext/context.py b/pycontext/context.py index c94f9d3..e5a0cdd 100644 --- a/pycontext/context.py +++ b/pycontext/context.py @@ -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): diff --git a/tests/test_context.py b/tests/test_context.py index 838f8d3..ea53ad6 100644 --- a/tests/test_context.py +++ b/tests/test_context.py @@ -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): From 2364a3fd984cef453d242148aab401f3355f98a5 Mon Sep 17 00:00:00 2001 From: Miroslav Shubernetskiy Date: Thu, 11 May 2017 11:01:44 -0400 Subject: [PATCH 2/2] removing new line in HISTORY [ci skip] --- HISTORY.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 3255f32..dccabc8 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,7 +7,6 @@ History ~~~~~~~~~~~~~~~~~~ * Add attribute support - * Add make watch target 0.1.0 (2017-03-22)