mirror of
https://github.com/xonsh/xonsh.git
synced 2025-03-04 08:24:40 +01:00
commit
6a0b9bd61d
3 changed files with 34 additions and 3 deletions
16
news/sub.rst
Normal file
16
news/sub.rst
Normal file
|
@ -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
|
11
tests/test_lazyasd.py
Normal file
11
tests/test_lazyasd.py
Normal file
|
@ -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']
|
||||||
|
|
|
@ -19,7 +19,7 @@ class LazyObject(object):
|
||||||
load : function with no arguments
|
load : function with no arguments
|
||||||
A loader function that performs the actual object construction.
|
A loader function that performs the actual object construction.
|
||||||
ctx : Mapping
|
ctx : Mapping
|
||||||
Context to replace the LazyAndSelfDestructiveObject instance in
|
Context to replace the LazyObject instance in
|
||||||
with the object returned by load().
|
with the object returned by load().
|
||||||
name : str
|
name : str
|
||||||
Name in the context to give the loaded object. This *should*
|
Name in the context to give the loaded object. This *should*
|
||||||
|
@ -56,6 +56,10 @@ class LazyObject(object):
|
||||||
obj = self._lazy_obj()
|
obj = self._lazy_obj()
|
||||||
yield from obj
|
yield from obj
|
||||||
|
|
||||||
|
def __getitem__(self, item):
|
||||||
|
obj = self._lazy_obj()
|
||||||
|
return obj[item]
|
||||||
|
|
||||||
|
|
||||||
class LazyDict(abc.MutableMapping):
|
class LazyDict(abc.MutableMapping):
|
||||||
|
|
||||||
|
@ -81,7 +85,7 @@ class LazyDict(abc.MutableMapping):
|
||||||
A mapping of loader function that performs the actual value
|
A mapping of loader function that performs the actual value
|
||||||
construction upon acces.
|
construction upon acces.
|
||||||
ctx : Mapping
|
ctx : Mapping
|
||||||
Context to replace the LazyAndSelfDestructiveDict instance in
|
Context to replace the LazyDict instance in
|
||||||
with the the fully loaded mapping.
|
with the the fully loaded mapping.
|
||||||
name : str
|
name : str
|
||||||
Name in the context to give the loaded mapping. This *should*
|
Name in the context to give the loaded mapping. This *should*
|
||||||
|
@ -145,7 +149,7 @@ class LazyBool(object):
|
||||||
load : function with no arguments
|
load : function with no arguments
|
||||||
A loader function that performs the actual boolean evaluation.
|
A loader function that performs the actual boolean evaluation.
|
||||||
ctx : Mapping
|
ctx : Mapping
|
||||||
Context to replace the LazyAndSelfDestructiveDict instance in
|
Context to replace the LazyBool instance in
|
||||||
with the the fully loaded mapping.
|
with the the fully loaded mapping.
|
||||||
name : str
|
name : str
|
||||||
Name in the context to give the loaded mapping. This *should*
|
Name in the context to give the loaded mapping. This *should*
|
||||||
|
|
Loading…
Add table
Reference in a new issue