Skip to content

Keys being renamed by safe_load  #840

Closed
@CraigBurden

Description

@CraigBurden

I have a YAML file:

criteria:
  sensor: 
    positive:
      accuracy: [-0.08, 0.08]
      range: [0.15, 0.3]
    negative:
      accuracy: [-0.08, 0.08]
      range: [0.05, 0.3]
  power_domain:
    off: [0, 3.4]
    on: [3, 3.4]

When I run this though yaml.safe_load(), I get the following:

{'criteria': {'sensor': {'positive': {'accuracy': [-0.08, 0.08], 'range': [0.15, 0.3]}, 'negative': {'accuracy': [-0.08, 0.08], 'range': [0.05, 0.3]}}, 'power_domain': {False: [0, 3.4], True: [3, 3.4]}}}

Notice the 'power_domain': {False: [0, 3.4], True: [3, 3.4]} in particular.

safe_load() is renaming the keys from on to True and off to False.
I do understand why the renaming happens in the case of a value, but it doesn't make much sense in the case of a key

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions