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

Aliases that ruyaml thinks are unreferenced seem to be dropped #50

Open
gfokkema opened this issue Mar 4, 2021 · 0 comments
Open

Aliases that ruyaml thinks are unreferenced seem to be dropped #50

gfokkema opened this issue Mar 4, 2021 · 0 comments

Comments

@gfokkema
Copy link

gfokkema commented Mar 4, 2021

I'm noticing some surprising behaviour where ruyaml seems to drop aliases that it thinks are not referenced.
I think this causes issues when dealing with duplicate merge keys as described in #43 for example.

Using this sample function to spot differences between input and output:

yaml = ruyaml.YAML(typ='rt')
yaml.allow_duplicate_keys = True
def read(srcdata):
    with io.StringIO() as buf:
        yaml.dump(yaml.load(srcdata), buf)
        dstdata = buf.getvalue()
    sys.stdout.writelines(difflib.unified_diff(srcdata.splitlines(True), dstdata.splitlines(True)))

When using the "correct" merge syntax as mentioned in #43:

read('''\
testa: &test1
  a: 1
testb: &test2
  a: 2
testc: &test3
  a: 3

data:
  <<: [*test1, *test2]
  c: 3
''')

I get these results:

--- 
+++ 
@@ -2,7 +2,7 @@
   a: 1
 testb: &test2
   a: 2
-testc: &test3
+testc:
   a: 3
 
 data:

And when using the "incorrect" syntax, things become more surprising:

read('''\
testa: &test1
  a: 1
testb: &test2
  a: 2
testc: &test3
  a: 3

data:
  <<: *test1
  <<: *test2
  <<: *test3
  c: 3
''')

I get these results:

--- 
+++ 
@@ -1,12 +1,11 @@
 testa: &test1
   a: 1
-testb: &test2
+testb:
   a: 2
 testc: &test3
   a: 3
 
 data:
   <<: *test1
-  <<: *test2
   <<: *test3
   c: 3

Any ideas what could be the cause or suggestions on how to deal with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant