lisa-lab/pylearn2

[enhancement] yaml_parser.py

Closed this issue · 3 comments

TNick commented

Hello,
This message would probably be more suited to dev mailing list.
Please let me know if you are interested in a pull request for following issues:


additional environment that is passed to yaml_parse.load() and yaml_parse.load_path() is only used in
multi_constructor_pkl. As a result strings processed elsewhere (as normal string values, for example) will throw an exception if the key is not in the environment.
By replacing this line :

 return preprocess(proxy)

with this

 return preprocess(proxy, additional_environ)

those other strings would see the custom dictionary.


On a related issue, !float can be made aware of os/custom values by replacing this part:

 value = loader.construct_scalar(node)
 return float(value)

with this one:

 value = loader.construct_scalar(node)
 return float(preprocess(value, additional_environ))

Still regarding the custom dictionary that can be passed to yaml_parse.load() and yaml_parse.load_path(): right now the user must provide all values as strings because of the way string_utils.preprocess() works. One solution to this is to modify load():

    # preprocess in string_utils assumes strings so we are making
    # all entries strings here
    if not environ is None:
        for k in environ.keys():
            environ[k] = str(environ[k])

    additional_environ = environ

thus allowing one to write

environ = {'abcd': 1.1}

instead of

environ = {'abcd': '1.1'}

A matter of taste, no doubt, just as my extensive use of code blocks. :)

@dwf, would you mind having a look? I'm not really familiar with the YAML parser.

TNick commented

I just found this thread (last message) that's probably related to this issue.

TNick commented

These things are implemented now in TNick/pyl2extra.
Closing this issue.