Code review comment for lp:~hazmat/pyjuju/fast-yaml

Revision history for this message
Martin Packman (gz) wrote :

Looks like a good improvement, I like that this also sorts out the
confusion over whether to use dump/load or safe_dump/safe_load at the
same time.

I would have been tempted to name the wrapper module juju.lib.yaml to
avoid touching most lines, but this way means you did look at all the
callers at least.

There are several callsites that still use the yaml module functions and
pass in a Loader or Dumper, apart from the one noted below, shouldn't
they all be changed to using juju.lib for consistency?

https://codereview.appspot.com/6493100/diff/1/juju/charm/config.py
File juju/charm/config.py (right):

https://codereview.appspot.com/6493100/diff/1/juju/charm/config.py#newcode80
juju/charm/config.py:80: raw_data = yaml.load(data,
Loader=yaml.CSafeLoader)
Why not use dump from juju.lib here rather than specifying the loader?
Will need the yaml import for the Mark below anyway, but seems best to
consistently use the same loader.

https://codereview.appspot.com/6493100/diff/1/juju/control/constraints_get.py
File juju/control/constraints_get.py (right):

https://codereview.appspot.com/6493100/diff/1/juju/control/constraints_get.py#newcode73
juju/control/constraints_get.py:73: yaml.dump(result, sys.stdout,
Dumper=yaml.CSafeDumper)
I'd dump using the juju.lib function and write to stout separately
afterwards here.

https://codereview.appspot.com/6493100/diff/1/juju/control/status.py
File juju/control/status.py (right):

https://codereview.appspot.com/6493100/diff/1/juju/control/status.py#newcode581
juju/control/status.py:581: data, filelike, default_flow_style=False,
Dumper=yaml.CSafeDumper)
This looks like the only place that really wants extra args to dump,
leaving this as a special case seems fine.

https://codereview.appspot.com/6493100/diff/1/juju/lib/serializer.py
File juju/lib/serializer.py (right):

https://codereview.appspot.com/6493100/diff/1/juju/lib/serializer.py#newcode5
juju/lib/serializer.py:5: def dump(*args, **kw):
I'd be tempted to make this just take a dict rather than passing through
args and kwargs.

https://codereview.appspot.com/6493100/diff/1/juju/lib/serializer.py#newcode9
juju/lib/serializer.py:9: def load(*args, **kw):
Likewise, would make this just take a string.

https://codereview.appspot.com/6493100/

« Back to merge proposal