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

[FIX] yaml: Specify loader to YAML constructors #28

Merged
merged 1 commit into from
Apr 26, 2019
Merged

Conversation

samueljsb
Copy link

@samueljsb samueljsb commented Apr 26, 2019

pyYAML 5.1 is now the distro version. This introduces the FullLoader as the default loader used with yaml.load(…), however the default loader for yaml.add_constructor(…) has not been updated (this is a known issue: yaml/pyyaml#274).

This commit specifies the loader to be used when adding constructors, using the FullLoader if it exists and the older Loader if not (i.e. depending on which version of pyYAML is installed).

Task: 3958

@samueljsb samueljsb requested a review from spenced April 26, 2019 11:16
for tag, constructor in constructors:
try:
# pyYAML v5.1 requires a loader to be set and does not include a default for add_constructor.
yaml.add_constructor(tag, constructor, Loader=yaml.FullLoader)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restricting the code in the try block to just determining if yaml.FullLoader is available eliminates any AttributeError escaping from the add_constructor call as a potential reason for executing the except block. The add_constructor with Loader can then be in an else.

@samueljsb samueljsb force-pushed the task/3958 branch 2 times, most recently from 570f3cd to 2f3d550 Compare April 26, 2019 12:57
pyYAML 5.1 is now the distro version. This introduces the FullLoader as
the default loader used with yaml.load(…), however the default loader for
yaml.add_constructor(…) has not been updated (This is a known issue:
yaml/pyyaml#274).
This commit specifies the loader to be used when adding constructors,
using the FullLoader if it exists and the older Loader if not (i.e.
depending on which version of pyYAML is installed).

Task: 3958

Signed-off-by: Samuel Searles-Bryant <[email protected]>
@samueljsb samueljsb changed the title [FIX] yaml: Add loader to constructors for pyYAML>=5.1 [FIX] yaml: Specify loader to YAML constructors Apr 26, 2019
@samueljsb samueljsb requested a review from spenced April 26, 2019 13:00
@samueljsb samueljsb merged commit c3550f2 into udes-11.0 Apr 26, 2019
@samueljsb samueljsb deleted the task/3958 branch April 26, 2019 13:07
@samueljsb samueljsb restored the task/3958 branch April 26, 2019 15:22
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

Successfully merging this pull request may close these issues.

2 participants