Skip to content
This repository has been archived by the owner on Oct 6, 2020. It is now read-only.

Incorrect advice provided with ruamel.yaml #14

Closed
AWegnerGitHub opened this issue Jul 22, 2019 · 1 comment
Closed

Incorrect advice provided with ruamel.yaml #14

AWegnerGitHub opened this issue Jul 22, 2019 · 1 comment

Comments

@AWegnerGitHub
Copy link

Using the example provided by ruamel.yaml for version > 0.15:

from pathlib import Path
from ruamel.yaml import YAML

yaml = YAML(typ="safe")
yaml.default_flow_style = False
data = yaml.load("abc: 1")
out = Path("/tmp/out.yaml")
yaml.dump(data, out)

Running dlint provides the following output:

$ python -m flake8 --select=DUO yaml_test.py 
yaml_test.py:6:8: DUO109 improper use of "yaml" parsing function, please use "safe_*" equivalent
yaml_test.py:8:1: DUO109 improper use of "yaml" parsing function, please use "safe_*" equivalent

If that advice is followed, the script doesn't work, since ruamel.yaml no longer has those functions:

$ python yaml_test.py 
Traceback (most recent call last):
  File "yaml_test.py", line 6, in <module>
    data = yaml.safe_load("abc: 1")
AttributeError: 'YAML' object has no attribute 'safe_load'
@mschwager
Copy link
Collaborator

Good catch! One of the general improvements needed in Dlint is better handling of from imports bringing names into the namespace (#1, #16). I'd say this follows a similar trend.

One quick way to fix this would be using a different variable name, e.g.

...
ruamel_yaml = YAML(typ="safe")
ruamel_yaml.default_flow_style = False
data = ruamel_yaml.load("abc: 1")
...

Dlint is getting confused with the variable name vs. the traditional YAML module name of yaml. Regardless, this should be fixed, so I'll track this along with other from import namespace improvements.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants