# Buggy code
def __init__(self, loaders, ctx, name):
    """Dictionary like object that lazily loads its values from an initial
    dict of key-loader function pairs.  Each key is loaded when its value
    is first accessed. Once fully loaded, this object 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 bunch of regular
    expressions until they are actually used::

        RES = LazyDict({
                'dot': lambda: re.compile('.'),
                'all': lambda: re.compile('.*'),
                'two': lambda: re.compile('..'),
                }, globals(), 'RES')

    Parameters
    ----------
    loaders : Mapping of keys to functions with no arguments
        A mapping of loader function that performs the actual value
        construction upon acces.
    ctx : Mapping
        Context to replace the LazyAndSelfDestructiveDict instance in
        with the the fully loaded mapping.
    name : str
        Name in the context to give the loaded mapping. This *should*
        be the name on the LHS of the assignment.
    """
    self._loaders = loaders
    self._ctx = ctx
    self._name = name
    self._d = type(loaders)()  # make sure to return the same type


# 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, loaders, ctx, name):
    """Dictionary like object that lazily loads its values from an initial
    dict of key-loader function pairs.  Each key is loaded when its value
    is first accessed. Once fully loaded, this object 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 bunch of regular
    expressions until they are actually used::

        RES = LazyDict({
                'dot': lambda: re.compile('.'),
                'all': lambda: re.compile('.*'),
                'two': lambda: re.compile('..'),
                }, globals(), 'RES')

    Parameters
    ----------
    loaders : Mapping of keys to functions with no arguments
        A mapping of loader function that performs the actual value
        construction upon acces.
    ctx : Mapping
        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*
        be the name on the LHS of the assignment.
    """
    self._loaders = loaders
    self._ctx = ctx
    self._name = name
    self._d = type(loaders)()  # make sure to return the same type