Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Mypy with Ruamel.yaml

I am attempting to use MyPy with modules that use ruamel.yaml and Mypy cannot find ruamel.yaml even though Python has no problem finding it. I am puzzled because I can't find a module called YAML.py or class called YAML either, even though these statements work in Python:

from ruamel.yaml import YAML
yaml = YAML()
x = yaml.load()

What do I need to do to get MyPy to recognize ruamel.yaml?

like image 531
Jonathan Avatar asked Oct 17 '22 13:10

Jonathan


1 Answers

A workaround is to run without the incremental logic of mypy:

python -m mypy --no-incremental myfile.py

Background

There is a known issue in mypy, see here.

In summary:

Something is not working with the incremental logic of mypy when it is encountering ruamel.

  • When you run it once, all goes ok. This is the command: python -m mypy myfile.py

  • Then, when you run it again, you get an error:

    error: Skipping analyzing 'ruamel': found module but no type hints or library stubs [import]

  • Then, when you run it again, it all goes ok

  • etc.

like image 191
Arjaan Buijk Avatar answered Oct 21 '22 05:10

Arjaan Buijk