suned / pfun

Functional, composable, asynchronous, type-safe Python.
https://pfun.dev/
MIT License
151 stars 14 forks source link

problems getting mypy to work with pfun (Cannot find module named 'pfun.io') #36

Closed michelrandahl closed 4 years ago

michelrandahl commented 4 years ago

First off, cool library and nice docs and examples :+1:

However, I am having problems making it work with mypy. It might be something with my setup or my lack of knowledge about mypy, -in that case the outcome might be some more value to add to the readme for other potential users :).

I am simply trying to run mypy on a file mytest.py which contains following lines

from pfun.io import get_line, put_line, IO

def hello(foo: str) ->IO[None]:
    return put_line('hello ' + foo)

hello('sir').run()

I get following error output when I try to run mypy on it

$ mypy mytest.py 
mytest.py:1: error: Cannot find module named 'pfun.io'
mytest.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)

I have a mypy.ini file in the same directory as mytest.py, and it contains:

[mypy]
plugins = pfun.mypy_plugin

Besides that, I am running NixOs and I am using a python virtualenv which contains following packages:

$ pip freeze
appdirs==1.4.3
astor==0.8.0
beautifulsoup4==4.8.1
bs4==0.0.1
certifi==2019.9.11
chardet==3.0.4
colorama==0.4.1
funcparserlib==0.3.6
hy==0.17.0+100.gf8d3826
idna==2.8
mypy==0.740
mypy-extensions==0.4.3
pfun==0.5.1
pythonping==1.0.4
requests==2.22.0
rply==0.7.7
soupsieve==1.9.4
toolz==0.10.0
typed-ast==1.4.0
typing-extensions==3.7.4.1
urllib3==1.25.6
youtube-dl==2019.7.16

and python version

$ python --version
Python 3.7.3

I have tried various things after reading a bit in the mypy docs, but nothing really helped. At first I suspected that mypy wasn't picking up on the mypy.ini file, but then I tried adding ignore_missing_imports = True and then it reported success for mytest.py (because it was happily ignoring pfun). I have also verified that there is indeed a file mypy_plugin.py inside pfun in the site-packages of my virtualenv.

Is there something obvious that I am missing?.. Or could the problem be something with my setup? (for example some environment variable pointing to something that doesn't exist in NixOs...)

suned commented 4 years ago

You are correct, I think the problem is that pfun is actually not PEP 561 compliant. Fix is incoming :)

suned commented 4 years ago

Just released 0.5.2, should be fixed in this version (https://pypi.org/project/pfun/0.5.2/). Please report back 😄

michelrandahl commented 4 years ago

it works, yay :+1: