mk-fg / pretty-yaml

PyYAML-based module to produce a bit more pretty and readable YAML-serialized data
Do What The F*ck You Want To Public License
135 stars 29 forks source link

dump() arguments: stream vs dst #44

Closed koct9i closed 1 year ago

koct9i commented 1 year ago

There is tiny incompatibility with PyYAML:

PyYAML: dump(data, stream=None, ...) https://github.com/yaml/pyyaml/blob/main/lib/yaml/__init__.py#L248

pretty-yaml: dump(data, dst=None, ...) https://github.com/mk-fg/pretty-yaml/blob/master/pyaml/__init__.py#L164

As a result:

>>> yaml.dump({}, stream=sys.stdout)
{}

>>> pyaml.dump({}, stream=sys.stdout)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/xxx/.local/lib/python3.10/site-packages/pyaml/__init__.py", line 181, in dump
    yaml.dump_all( data, buff, Dumper=Dumper,
TypeError: dump_all() got multiple values for argument 'stream'
mk-fg commented 1 year ago

Yeah, it's unfortunate, but that's the current API, and I don't think this is a good reason to break it. Also, dst option works a bit differently from how stream does in pyyaml.

mk-fg commented 1 year ago

Oh, although guess stream= can be easily supported alongside dst=, which didn't occur to me at first.

mk-fg commented 1 year ago

Should be fixed in 23.9.0, by checking if either stream or dst is passed (but not both), and defaulting to the same old "return str" behavior. Thanks for reporting!