Modify

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:
Cc:

Description

Hello,

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:


#!/usr/bin/python

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 "./yamlerr.py", line 15, in <module>

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

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

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

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

dumper.represent(data)

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

self.serialize(node)

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

self.serialize_node(node, None, None)

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

self.serialize_node(value, node, key)

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

self.serialize_node(key, node, None)

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

style=node.style))

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

self.state()

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

return self.expect_block_mapping_key(first=True)

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

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

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

self.process_tag()

File "/usr/lib/python2.6/dist-packages/yaml/emitter.py", line 469, in process_tag

self.style = self.choose_scalar_style()

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

if self.event.style and self.event.style in '|>':

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


Thanks in advance for your feedback.

Attachments

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.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
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'
Author


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

 
Note: See TracTickets for help on using tickets.