【问题标题】:stub files present in package, still mypy complains: Cannot find implementation包中存在存根文件,仍然 mypy 抱怨:找不到实现
【发布时间】:2022-06-11 08:54:20
【问题描述】:

包 1

我创建了一个包 my_utils 并使用 mypy 实用程序 stubgen 生成了 stud 文件

stubgen -p my_utils
# >>> Processed 2 modules
# >>> Generated files under out/my_utils/

将存根移至包根目录

mv out/my_utils/* my_utils

mypy 很高兴

mypy my_utils
# >>> # Success: no issues found in 2 source files

包 2

包 2 有 my_utils 作为依赖项,所以我使用诗歌安装了我的 my_utils

poetry add git+ssh://git@github.com/username/my-utils.git

我的虚拟环境库具有以下包结构:

my_utils
├── __init__.py
├── __init__.pyi
├── os.py
├── os.pyi
└── py.typed

但当我检查我的包裹 2 时 mypy 仍然会抱怨

mypy r26/bwf_converter.py
# r26/bwf_converter.py:12: error: Cannot find implementation or library stub for module named "my_utils.os"

__init__.pyi 为空,os.pyi 有以下内容:

import csv
import json
from typing import Dict, List, Literal, Union

OutputProc = Literal["wait", "raw", "json", "csv", ""]
StdType = Literal["stderr", "stdout"]
JsonContent = Dict[str, str]
CsvContent = List[Dict[str, str]]

class PopenWrapper:
    cmd: Union[str, List[str]]
    ouput_proc: Literal["wait", "raw", "json", "csv", ""]
    log_output: bool
    kwargs: Dict[str, str]
    def __init__(self, cmd: Union[str, List[str]], ouput_proc: OutputProc = ..., log_output: bool = ..., **kwargs: Dict[str, str]) -> None: ...
    def run(self) -> Union[bool, str, CsvContent, JsonContent]: ...

如果有人能提示我我做错了什么......

【问题讨论】:

    标签: python types mypy stub


    【解决方案1】:

    生成存根文件和py.typed 标记后,需要重新安装第三方包。运行

    poetry run py -m pip install --ignore-installed <package>
    

    然后mypy 将看到存根。

    【讨论】:

      猜你喜欢
      • 2011-01-09
      • 2022-01-10
      • 2021-03-04
      • 1970-01-01
      • 2020-05-15
      • 2013-03-09
      • 1970-01-01
      • 2021-09-29
      • 2023-02-10
      相关资源
      最近更新 更多