Support `!!python/frozenset`

Issue #53 new
Wil Cooley
created an issue

Among all of the built-in types supported by PyYAML, the only one I am finding myself missing is the frozenset type. I want this specifically because it is hashable, so I can use it as a dictionary key. I am currently able to use !!python/object/apply:frozenset, which works fine, but given that frozenset is built-in like set, it makes sense to support !!python/fronzenset. (If nothing else, it would be nice to document it and save others the trouble of figuring it out.)

Additionally, would it make sense to coerce a YAML !!set to a !!python/frozenset when a hashable key is needed? Since you cannot currently use a !!set as a key, adding this ability would be backwards-compatible, I think, so it would not be a breaking change.

My particular use is to model Neo4j graph nodes for py2neo, which have a set of labels and a mapping of properties.

nodes:
    by_label:
        ? !!python/object/apply:frozenset
            ? 'character'
            ? 'major'
        :
          -   name: "Beezus Quimby"
              description: "Older Sister"
          -   name: "Ramona Quimby"
              description: "Pesky Little Sister"

Comments (0)

  1. Log in to comment