我有一个文件test.py
,其中仅包含行import black
。运行mypy test.py
时,出现以下错误:
test.py:1: error: Skipping analyzing 'black': found module but no type hints or library stubs
test.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)
但是,当我查看source到black
时,似乎所有内容都有类型提示。 [我需要在mypy
中进行不同的操作以使其在导入black
时使用类型提示吗?
环境设置:
conda create -n test python=3.7 -y
conda activate test
pip install black mypy
编辑-来自the link mentioned in the error message:
[Mypy将不会尝试推断您已安装的任何第三方库的类型,除非它们声明自己是符合PEP 561的存根软件包或已在类型库中注册了它们]]
我以为
black
已满足这些要求之一,但似乎没有在typeshed上注册。从here看来,一个软件包必须具有py.typed
文件才能与PEP 561兼容并带有内联注释,而black
似乎也没有。我的问题仍然存在-鉴于
black
中已经存在键入信息,我如何(无需在某个地方批准PR)让mypy
使用该信息?
我看不到有关py.typed
文件的任何详细信息-如果那只是一个空文件,并且仅考虑其存在,我想我可以在某个地方创建它,然后输入将起作用?
我有一个文件test.py,其中只包含行import black。当我运行mypy test.py时,出现以下错误:test.py:1:错误:跳过分析'black':找到了模块,但没有类型提示或...
在安装目录中创建一个名为py.typed
的空文件就足够了:
cd ~/anaconda/envs/test/lib/python3.7/site-packages # or wherever your packages are installed
# black.py is directly in site-packages, but py.typed needs to be in a directory for the module
mkdir black
touch black/py.typed