-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Remove logic converting empty or falsy YAML to empty dict #103912
Conversation
homeassistant/util/yaml/loader.py
Outdated
if result is None: | ||
return NodeDictClass() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like quite the hack, shouldn't the consumer handle this? We could also make our own extensions, i.e. !include
and friends, do this conversion and document it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kinda odd behavior in general, why would we map an empty files to an empty dict in the first place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's to make !include
and friends more user friendly by treating an empty yaml file as an empty dictionary.
I think we should handle this in config.py
though, not in our yaml loader.
Let's make this PR a draft until that's been clarified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did this indeed to ensure that the top-level data structure returend from a yaml.load is always a dictionary. Let's just say that we didn't always had config validation …
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch,
Thnx @emontnemery 👍
eca5bb4
to
aa835c7
Compare
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
I'm missing the reason for the refactor in the PR description. |
PR description updated to motivate the changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Proposed change
Remove logic from
yaml.loader.load_yaml
converting "falsy" files to empty dictRationale: Empty files, or files containing falsy data such as the number 0, False, an empty list etc. are valid yaml and there's no reason why they should be converted to an empty dict.
It's however a common case that we do want to load configuration files which must be dictionaries and which we do allow to be empty.
Add a new helper
yaml.loader.load_yaml_dict
for this case which:Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: