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

The loader transforms 'on' key to True #470

Closed
adelbke opened this issue Jan 4, 2021 · 1 comment
Closed

The loader transforms 'on' key to True #470

adelbke opened this issue Jan 4, 2021 · 1 comment
Labels

Comments

@adelbke
Copy link

adelbke commented Jan 4, 2021

I'm trying to parse a github Actions yaml file that has a key named 'on' like shown below:

candidate.yaml

name: action code

on: # this is the key causing the issue, it's translated to 'True' when loaded by pyyaml
  push:
    branches:
      - master

jobs:
  build:

    runs-on: ubuntu-16.04

    steps:
# Action Steps

tested on:
Python version: 3.8.6
Ubuntu 20.10

here's the code used:

import yaml
# candidate.yaml is the name of the file up above
data = yaml.load(open('candidate.yaml','r'))
print(yaml.dump(data))

here's the output:

name: action code)
true: # here it says 'true' instead of 'on' in the original file
  push:
    branches:
    - master
jobs:
  build:
    runs-on: ubuntu-16.04
    steps: null

as you can see the 'on' key has been replaced by 'True' on this file

@nitzmahone
Copy link
Member

This is the expected behavior from a YAML 1.1 compliant library (which pyyaml is). You can modify this behavior by replacing the boolean implicit resolver with one that excludes on and off in a custom loader (or by modifying the existing loaders).

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

3 participants