Ticket #215 (new defect)

Opened 2 years ago

Last modified 13 months ago

Exception in yaml.dump() with Dumper and default_style=True, but not with CDumper

Reported by: sylvain Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:



I meet a reproducible Exception when dumping a python dictionary with default_style=True. This occurs when Dumper=yaml.Dumper, but not with the CDumper.

My setup:

python-yaml, version: 3.09-5 python2.6.6, libyaml-0-2

A simple script to reproduce this exception:


import yaml

str_in = """ test:

a: b


d = yaml.load(str_in, Loader=yaml.Loader)

print yaml.dump(d, Dumper=yaml.CDumper) print yaml.dump(d, Dumper=yaml.CDumper, default_style=True) print yaml.dump(d, Dumper=yaml.Dumper) # This line causes an exception print yaml.dump(d, Dumper=yaml.Dumper, default_style=True)

The exception is as follows:

Traceback (most recent call last):

File "./", line 15, in <module>

print yaml.dump(d, Dumper=yaml.Dumper, default_style=True)

File "/usr/lib/python2.6/dist-packages/yaml/", line 175, in dump

return dump_all([data], stream, Dumper=Dumper, kwds)

File "/usr/lib/python2.6/dist-packages/yaml/", line 165, in dump_all


File "/usr/lib/python2.6/dist-packages/yaml/", line 34, in represent


File "/usr/lib/python2.6/dist-packages/yaml/", line 54, in serialize

self.serialize_node(node, None, None)

File "/usr/lib/python2.6/dist-packages/yaml/", line 108, in serialize_node

self.serialize_node(value, node, key)

File "/usr/lib/python2.6/dist-packages/yaml/", line 107, in serialize_node

self.serialize_node(key, node, None)

File "/usr/lib/python2.6/dist-packages/yaml/", line 90, in serialize_node

File "/usr/lib/python2.6/dist-packages/yaml/", line 110, in emit


File "/usr/lib/python2.6/dist-packages/yaml/", line 389, in expect_first_block_mapping_key

return self.expect_block_mapping_key(first=True)

File "/usr/lib/python2.6/dist-packages/yaml/", line 399, in expect_block_mapping_key

self.expect_node(mapping=True, simple_key=True)

File "/usr/lib/python2.6/dist-packages/yaml/", line 238, in expect_node


File "/usr/lib/python2.6/dist-packages/yaml/", line 469, in process_tag = self.choose_scalar_style()

File "/usr/lib/python2.6/dist-packages/yaml/", line 501, in choose_scalar_style

if and in '|>':

TypeError?: 'in <string>' requires string as left operand, not bool

Thanks in advance for your feedback.


Change History

comment:1 Changed 13 months ago by anonymous

This scenario does not seem valid, as default_style requires to be string, not a boolean.

You might use default_flow_style rather than default_flow_style. However, the problem might be that the CDumper does not seem to honor that parameter.


Add a comment

Modify Ticket

Change Properties
<Author field>
as new
as The resolution will be set. Next status will be 'closed'
to The owner will be changed from xi. Next status will be 'new'
The owner will be changed from xi to anonymous. Next status will be 'assigned'

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

Note: See TracTickets for help on using tickets.