Modify

Ticket #64 (closed task: fixed)

Opened 7 years ago

Last modified 7 years ago

yaml.dump and indentation:

Reported by: lal.george@… Owned by: xi
Priority: low Component: pyyaml
Severity: normal Keywords:
Cc:

Description

In python, when I have :


y = {'x' : 3, z : [{'val' : 3}, {'val' : 4}]} yaml.dump(y, default_flow_style=False)


The result is: 'x: 3\nz:\n- val: 3\n- val: 4\n'

I believe there should be a space before each hypen.

Best,

Lal

Attachments

Change History

comment:1 Changed 7 years ago by xi

  • Status changed from new to closed
  • Resolution set to invalid

The output is correct, see the production l-block-seq-entry(n,c) and Example 10.4:

 http://yaml.org/spec/cvs/current.html#l-block-seq-entry(n,c)

comment:2 Changed 7 years ago by lageorge@…

  • Status changed from closed to reopened
  • Resolution invalid deleted

Unfortunately, I don't understand the notation very well; but l-block-seq-entry(n,c) ::= s-indent(seq-spaces(n,c)) "-" ...

Since a new block is being started, won't there be an s-indent?

Best,

Lal

p.s. The java version of yaml does not like the dump produced by PyYaml?.

comment:3 Changed 7 years ago by xi

  • Status changed from reopened to closed
  • Resolution set to invalid

Read the next paragraph after the production:

People read the “-” character as part of the indentation. Hence, block sequence entries require one less space of indentation, unless the block sequence is nested within another block sequence (hence the need for the block-in context and block-out context).

See also the example in the specification:

block:
- one
-
·- two

P.S. The YAML loader in Java must be broken then.

comment:4 Changed 7 years ago by anonymous

  • Priority changed from highest to low
  • Status changed from closed to reopened
  • Resolution invalid deleted
  • Type changed from defect to task

Thanks for the quick response ...

I believe you and PyYaml? are correct. The Java implementation is returning null for z in:

'x: 3\nz:\n- val: 3\n- val: 4\n'

Do you know a work around I could use? Perhaps I could turn this feature off, by always having PyYaml? emit " -" wherever it emits "-".

Thanks for your help.

Best,

Lal

comment:5 Changed 7 years ago by xi

  • Status changed from reopened to closed
  • Resolution set to fixed

You can use the following code:

import yaml

class MyDumper(yaml.Dumper):

    def increase_indent(self, flow=False, indentless=False):
        return super(MyDumper, self).increase_indent(flow, False)

y = {'x' : 3, 'z' : [{'val' : 3}, {'val' : 4}]}

print yaml.dump(y, Dumper=MyDumper, default_flow_style=False)
View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.