# Buggy code
def __init__(self, load, ctx, name):
    """Lazily loads an object via the load function the first time an
    attribute is accessed. Once loaded it will replace itself in the
    provided context (typically the globals of the call site) with the
    given name.

    For example, you can prevent the compilation of a regular expreession
    until it is actually used::

        DOT = LazyObject((lambda: re.compile('.')), globals(), 'DOT')

    Parameters
    ----------
    load : function with no arguments
        A loader function that performs the actual object construction.
    ctx : Mapping
        Context to replace the LazyAndSelfDestructiveObject instance in
        with the object returned by load().
    name : str
        Name in the context to give the loaded object. This *should*
        be the name on the LHS of the assignment.
    """
    self._lasdo = {
        "loaded": False,
        "load": load,
        "ctx": ctx,
        "name": name,
    }


# Traceback (TypeError)
~⟫ 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')

# Fixed code
def __init__(self, load, ctx, name):
    """Lazily loads an object via the load function the first time an
    attribute is accessed. Once loaded it will replace itself in the
    provided context (typically the globals of the call site) with the
    given name.

    For example, you can prevent the compilation of a regular expreession
    until it is actually used::

        DOT = LazyObject((lambda: re.compile('.')), globals(), 'DOT')

    Parameters
    ----------
    load : function with no arguments
        A loader function that performs the actual object construction.
    ctx : Mapping
        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*
        be the name on the LHS of the assignment.
    """
    self._lasdo = {
        "loaded": False,
        "load": load,
        "ctx": ctx,
        "name": name,
    }