Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing error while defining same alias #334

Open
whg517 opened this issue Sep 11, 2019 · 1 comment
Open

Parsing error while defining same alias #334

whg517 opened this issue Sep 11, 2019 · 1 comment
Labels

Comments

@whg517
Copy link

whg517 commented Sep 11, 2019

# encoding: utf-8

import yaml

doc = """%YAML 1.2
---
- config:
    filename: &filename xxx
  metadata:
    xx:
      file: *filename
- config:
    filename: &filename yyy
  metadata:
    xx:
      file: *filename
"""

yaml.load(doc, yaml.SafeLoader)
Traceback (most recent call last):
  File "/home/kevin/workspaces/develop/python/data_trans/tran_20190911/__init__.py", line 19, in <module>
    yaml.load(doc, yaml.SafeLoader)
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/__init__.py", line 114, in load
    return loader.get_single_data()
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/constructor.py", line 41, in get_single_data
    node = self.get_single_node()
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/composer.py", line 36, in get_single_node
    document = self.compose_document()
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/composer.py", line 55, in compose_document
    node = self.compose_node(None, None)
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/composer.py", line 82, in compose_node
    node = self.compose_sequence_node(anchor)
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/composer.py", line 111, in compose_sequence_node
    node.value.append(self.compose_node(node, index))
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/composer.py", line 84, in compose_node
    node = self.compose_mapping_node(anchor)
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/composer.py", line 133, in compose_mapping_node
    item_value = self.compose_node(node, item_key)
  File "/home/kevin/.virtualenvs/data_trans-La80qRSB/lib/python3.6/site-packages/yaml/composer.py", line 77, in compose_node
    "second occurrence", event.start_mark)
yaml.composer.ComposerError: found duplicate anchor 'filename'; first occurrence
  in "<unicode string>", line 4, column 15:
        filename: &filename xxx
                  ^
second occurrence
  in "<unicode string>", line 9, column 15:
        filename: &filename yyy
                  ^

Process finished with exit code 1

The Alias Nodes example by yaml spec is multi-anchor capable.

How do I need to use it correctly?

Thank you for your help.

@perlpunk
Copy link
Member

Duplicate of #100

@perlpunk perlpunk marked this as a duplicate of #100 Sep 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants