Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to tell mypy to include stubfile

Tags:

python

mypy

I'm playing around with mypy (version: 0.630) and I'm struggling to get it to see my stub file. Can anyone tell me what is wrong here:

My directory structure looks like this:

├── caesar.py
└── stubs
    └── caesar.pyi

caesar.py contains some valid python code. caesar.pyi contains the word bugger. I expect that when I run mypy I'll get an error. I run mypy like so:

export MYPYPATH=${PWD}/stubs
mypy caesar.py

There is no output (indicating success). What simple thing am I missing?

-- EDIT --

I then tried a little experiment by adding a few empty init files and changing the directory structure:

├── caesar
│   ├── caesar.py
│   └── __init__.py
├── mypy.sh
└── stubs
    ├── caesar
    │   ├── caesar.pyi
    │   └── __init__.pyi
    └── __init__.pyi

Then tried:

export MYPYPATH=${PWD}/stubs
mypy caesar/caesar.py

This changed nothing :/

-- EDIT --

mypy.ini now looks like:

[mypy]
python_version = 3.7
mypy_path=stubs
cache_dir=/dev/null

Running mypy like:

mypy --config-file mypy.ini caesar.py

directory tree:

├── caesar.py
├── mypy.ini
├── mypy.sh
└── stubs
    └── caesar.pyi

mypy version: 0.630

like image 294
Sheena Avatar asked Nov 08 '22 01:11

Sheena


1 Answers

I have been using a mypy.ini file, with success:

[mypy]
python_version = 3.6
mypy_path = /Users/rpg/projects/xplan/yeast-gates-data/stubs
cache_dir = /dev/null

I found the cache_dir setting was necessary in order to avoid mypy caching type definitions. I wasn't sure it was always refreshing the cache properly. Your config file looks fine; the only thing I can think of is that the quotes might

like image 61
Robert P. Goldman Avatar answered Nov 14 '22 23:11

Robert P. Goldman