Modify

Ticket #103 (closed defect: wontfix)

Opened 5 years ago

Last modified 29 hours ago

example from http://yaml.org/type/yaml.html fails to parse

Reported by: py4fun@… Owned by: xi
Priority: low Component: pyyaml
Severity: minor Keywords:
Cc:

Description

example from  http://yaml.org/type/yaml.html fails to parse. Is it a wrong example ? (I have found already a few...)

>>> text = open('yaml.yaml').read()
>>> print text
# The following node should NOT be serialized this way.
encoded YAML node :
 !!yaml '!' : '!type'
 !!yaml '&' : 12
 !!value = : value
# The proper way to serialize the above node is as follows:
node : !type &12 value

>>> print yaml.load(text)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\tools\Python25\lib\site-packages\yaml\__init__.py", line 58, in load
    return loader.get_single_data()
  File "C:\tools\Python25\lib\site-packages\yaml\constructor.py", line 44, in get_single_data
    return self.construct_document(node)
  File "C:\tools\Python25\lib\site-packages\yaml\constructor.py", line 53, in construct_document
    for dummy in generator:
  File "C:\tools\Python25\lib\site-packages\yaml\constructor.py", line 404, in construct_yaml_map
    value = self.construct_mapping(node)
  File "C:\tools\Python25\lib\site-packages\yaml\constructor.py", line 214, in construct_mapping
    return BaseConstructor.construct_mapping(self, node, deep=deep)
  File "C:\tools\Python25\lib\site-packages\yaml\constructor.py", line 139, in construct_mapping
    value = self.construct_object(value_node, deep=deep)
  File "C:\tools\Python25\lib\site-packages\yaml\constructor.py", line 94, in construct_object
    data = constructor(self, node)
  File "C:\tools\Python25\lib\site-packages\yaml\constructor.py", line 420, in construct_undefined
    node.start_mark)
yaml.constructor.ConstructorError: could not determine a constructor for the tag '!type'
  in "<string>", line 7, column 8:
    node : !type &12 value
           ^
>>>

Attachments

Change History

comment:1 Changed 5 years ago by xi

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

PyYAML complains about the tag !type since this is a custom tag and you have not provided a constructor for it so PyYAML doesn't know how to convert this node to a Python object.

Anyway, PyYAML does not provide a default constructor for !!yaml either so this example won't work even if you replace !type with, say, !!str. Here is the list of tags PyYAML supports out-of-box: http://pyyaml.org/wiki/PyYAMLDocumentation#YAMLtagsandPythontypes.

comment:2 Changed 29 hours ago by maskodok <galihadiputro87@…>

The only thing more I could hope for is documentation of all these features (other than reading through the code).  Cipto Junaedy Is this in process? Can I help? About  Unit Link Terbaik di Indonesia Commonwealth Life Investra Link

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.