From 55ec4d4afb34852889e4a26d40a6e9c35994fa12 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Mon, 27 Jun 2016 20:53:10 -0400 Subject: [PATCH 1/2] lazy object getitem --- tests/test_lazyasd.py | 11 +++++++++++ xonsh/lazyasd.py | 10 +++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/test_lazyasd.py diff --git a/tests/test_lazyasd.py b/tests/test_lazyasd.py new file mode 100644 index 000000000..d8105c4fe --- /dev/null +++ b/tests/test_lazyasd.py @@ -0,0 +1,11 @@ +"""Tests lazy and self destruictive objects.""" +from xonsh.lazyasd import LazyObject + +# +# LazyObject Tests +# + +def test_lazyobject_getitem(): + lo = LazyObject(lambda: {'x': 1}, {}, 'lo') + assert 1 == lo['x'] + diff --git a/xonsh/lazyasd.py b/xonsh/lazyasd.py index 33e0291dd..3af53cc92 100644 --- a/xonsh/lazyasd.py +++ b/xonsh/lazyasd.py @@ -19,7 +19,7 @@ class LazyObject(object): load : function with no arguments A loader function that performs the actual object construction. ctx : Mapping - Context to replace the LazyAndSelfDestructiveObject instance in + Context to replace the LazyObject instance in with the object returned by load(). name : str Name in the context to give the loaded object. This *should* @@ -56,6 +56,10 @@ class LazyObject(object): obj = self._lazy_obj() yield from obj + def __getitem__(self, item): + obj = self._lazy_obj() + return obj[item] + class LazyDict(abc.MutableMapping): @@ -81,7 +85,7 @@ class LazyDict(abc.MutableMapping): A mapping of loader function that performs the actual value construction upon acces. ctx : Mapping - Context to replace the LazyAndSelfDestructiveDict instance in + Context to replace the LazyDict instance in with the the fully loaded mapping. name : str Name in the context to give the loaded mapping. This *should* @@ -145,7 +149,7 @@ class LazyBool(object): load : function with no arguments A loader function that performs the actual boolean evaluation. ctx : Mapping - Context to replace the LazyAndSelfDestructiveDict instance in + Context to replace the LazyBool instance in with the the fully loaded mapping. name : str Name in the context to give the loaded mapping. This *should* From 4a2d927744be2e22f4477d6c87db3b1e845e43fb Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Mon, 27 Jun 2016 20:55:27 -0400 Subject: [PATCH 2/2] news --- news/sub.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 news/sub.rst diff --git a/news/sub.rst b/news/sub.rst new file mode 100644 index 000000000..e9f67206d --- /dev/null +++ b/news/sub.rst @@ -0,0 +1,16 @@ +**Added:** + +* LazyObjects will now load themselves on ``__getitem__()`` + +**Changed:** None + +**Deprecated:** None + +**Removed:** None + +**Fixed:** + +* Bug with setting hist size not being settable due to lazy object loading + has been resolved. + +**Security:** None