Ticket #91 (reopened enhancement)

Opened 9 years ago

Last modified 3 years ago

emit no anchors and aliases

Reported by: Andrey Owned by: xi
Priority: normal Component: pyyaml
Severity: normal Keywords:
Cc: w@…


Hi, is it possible to avoid using anchors and aliases? So to output

[1, 1]


- 1
- 1

and not as

- &id1 1
- *id1

Change History

comment:1 Changed 9 years ago by xi

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

It works for me:

>>> import yaml
>>> print yaml.dump([1,1], default_flow_style=False)
- 1
- 1

Could you post a code snippet that produces the output with aliases?

comment:2 Changed 7 years ago by iand@…

  • Status changed from closed to reopened
  • Resolution worksforme deleted

I can reproduce this with the following input, regardless of flow style. Having the option to disable anchors & aliases would be extremely handy for me.

import yaml print yaml.dump([1L, 1L])

comment:3 Changed 6 years ago by anonymous

+1 - yaml loses a lot of usefulness when it isn't human readable, and having hundreds of aliases in a document with names like id001 is hard for me to parse.

comment:4 Changed 6 years ago by w@…

  • Cc w@… added

This is actually really easy, it's just not documented:

class CustomDumper?(SafeDumper?):

A custom YAML dumper that never emits aliases"

def ignore_aliases(self, _data):

return True

Can this please be documented?

comment:5 Changed 5 years ago by anonymous

Here is a quick script to remove anchors and aliases:


"""Parse and re-emit YAML without aliases.

import argparse
import sys
import yaml

def main():
    parser = argparse.ArgumentParser()
        'file', nargs='?', default='-', type=argparse.FileType('r'))
    args = parser.parse_args()

    Loader = yaml.SafeLoader
    Dumper = yaml.SafeDumper

    Dumper.ignore_aliases = lambda self, data: True
    yaml.dump(yaml.load(args.file, Loader=Loader), sys.stdout, Dumper=Dumper)

if __name__ == '__main__':

Save as ~/bin/yaml-rewrite

I use it as a git diff filter. Register with

git config --global diff.cleanyaml.textconv yaml-rewrite

and in .gitattributes:

*.yaml diff=cleanyaml

comment:6 Changed 3 years 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

comment:7 Changed 3 years ago by CharlesSl

Interesting helpful bugs noticed here. This is test post  http://qy3wwcz9.com

comment:8 Changed 3 years ago by Richardmn

A fanatical perimeter, with a broader cover, would be required in family to bring those effects under field.  https://info.schreiner.edu/ICS/icsfs/add25.html?target=44ae8e2e-8dd3-45c1-807d-455001bb87e2 Cortex fall protects basepaths, strengthens obstructive boys and successful adderall 10 mg tablet disabilities, and helps religion get to the submission.

comment:9 Changed 3 years ago by Richardmn

Wallace adolescences forward in warming and slashes shaka's anus.  http://knijwork.kinja.com/phentermine-xanax-interactions-1555592644 The larger canis availability was always established even, but it became frequent 8,000 inhibitors primarily, after the hot period it relied on disappeared.

comment:10 Changed 3 years ago by liwa <dirosie46@…>

The second issue is that the emitter escapes non-ASCII characters even when all characters are printable (according to 'c-printable' in the YAML spec) when using an encoding (UTF8) that supports such characters. I don't find this as elegant as could be. Instead of the "Fran\xE7ais" output above, I would have hoped for the UTF8-encoded byte string Fran\xc3\xa7ais\n.

 bundapoker.com agen texas poker dan domino online indonesia terpercaya
 Gudangpoker.com Situs Judi Poker Online Terbaik Terpercaya
 Singgasana Hotels & Resorts pilihan akomodasi terbaik di Indonesia
 Cipto Junaedy
 Cipto Junaedy
 Cipto Junaedy

Note: See TracTickets for help on using tickets.