Repository: xonsh/xonsh

Issue:
Error when starting xonsh from xonsh ($XONSH_HISTORY_SIZE)
```
~⟫ xonsh
Traceback (most recent call last):
  File "/usr/bin/xonsh", line 3, in <module>
    main()
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 16446, in main
    args = premain(argv)
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 16431, in premain
    shell = builtins.__xonsh_shell__ = Shell(**shell_kwargs)
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 16185, in __init__
    kwargs.get('cacheall', False))
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 16227, in _init_environ
    debug_level=debug)
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 15871, in __init__
    load_builtins(execer=self, config=config, login=login, ctx=xonsh_ctx)
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 15711, in load_builtins
    builtins.__xonsh_env__ = ENV = Env(default_env(config=config, login=login))
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 11335, in __init__
    self[key] = val
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 11468, in __setitem__
    val = ensurer.convert(val)
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 6186, in to_history_tuple
    return to_history_tuple((m.group(1), m.group(3)))
  File "/usr/lib/python3.5/site-packages/xonsh/__amalgam__.py", line 6189, in to_history_tuple
    units, converter = HISTORY_UNITS[x[1]]
TypeError: 'LazyObject' object is not subscriptable
~⟫ xonfig
+------------------+----------+
| xonsh            | 0.4.2    |
| Python           | 3.5.1    |
| PLY              | 3.7      |
| have readline    | True     |
| prompt toolkit   | None     |
| shell type       | readline |
| pygments         | 2.1.3    |
| on posix         | True     |
| on linux         | True     |
| distro           | arch     |
| on darwin        | False    |
| on windows       | False    |
| on cygwin        | False    |
| is superuser     | False    |
| default encoding | utf-8    |
| git SHA          | None     |
+------------------+----------+
~⟫ $XONSH_HISTORY_SIZE
(10000, 'commands')
```



Discussion:
Hey, i can't seem to reproduce. Have you installed from current master? also my amalgam seems a little different as in miss-matching line numbers. Don't know if this will make a difference but you can try purging xonsh and reinstalling. Turning XONSH_DEBUG on would help too.

I run on release 0.4.2

To reproduce, this line must be in _.xonshrc_:

```
$XONSH_HISTORY_SIZE = (10000, 'commands')
```

This is likely an error with LazyObject not loading itself on `__getitem__()` calls.

It also seems like `xonfig wizard` says "invalid value" no matter what I type.

```
$XONSH_HISTORY_SIZE
[...]
default value: (8128, 'commands') or '8128 commands'
current value: (8128, 'commands')
>>> 10000 commands
Invalid input '10000 commands', please retry.
>>> '10000 commands'
Invalid input "'10000 commands'", please retry.
>>> (8128, 'commands')
Invalid input "(8128, 'commands')", please retry.
>>> 10000
Invalid input '10000', please retry.
```


Resolving patch:
diff --git a/xonsh/lazyasd.py b/xonsh/lazyasd.py
--- a/xonsh/lazyasd.py
+++ b/xonsh/lazyasd.py
@@ -19,7 +19,7 @@ def __init__(self, load, ctx, name):
         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 @@ def __iter__(self):
         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 @@ def __init__(self, loaders, ctx, name):
             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 @@ def __init__(self, load, ctx, name):
         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*


Test patch:
diff --git a/tests/test_lazyasd.py b/tests/test_lazyasd.py
new file mode 100644
--- /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']
+