python-3.x - mypy 跳过分析自己导入的模块并引发错误
问题描述
我似乎无法弄清楚为什么 mypy 在自己的模块导入时抛出错误。
$ python -m mypy ./reader/api/response/response.py
reader/api/response/response.py:5: error: Skipping analyzing 'reader.api.response.answer': found module but no type hints or library stubs
reader/api/response/response.py:5: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
response.py
从同一存储库中的另一个模块导入一个类
from __future__ import annotations
from typing import List
from dataclasses import dataclass
from reader.api.response.answer import Answer # <- mypy fails here.
@dataclass
class ReaderResponse:
...
的内容answer.py
是这样的:
from __future__ import annotations
from dataclasses import dataclass, fields
@dataclass
class Answer:
answer: str
score: float
source: str
url: str
type: str
...
为什么 mypy 认为我导入的模块中没有类型提示?我已在此处阅读有关缺少导入的文档,但不明白它是如何应用的。它不是第三方库。这是我自己的模块。
任何线索我在这里做错了什么?
谢谢你。
编辑:所以从命名空间包切换到常规包,并切换到相对导入(点导入)解决了我的问题。不完全确定为什么...
解决方案
推荐阅读
- c++ - 为什么-1等于整数-5的第4个字节?
- java - JWT authentication with spring and angular with null header
- c# - WinForms 圆环图和饼图标签背景元素颜色属性
- ajax - Loading AJAX Data on ShieldUI Data Grid
- integration - status=1&enc_response=command is mandatory. while integrating CCAvenue
- python - Seleniumbase 消息:元素
无法通过键盘访问
- java - 使用 CrudRepository.save(Entity) 使用 spring-data-jdbc 插入具有预定义 @ID 字段的实体
- c# - C#:成功登录后隐藏登录表单
- pandas - 在多列上运行 groupby agg 函数?
- python - PyQT5 'QPoint' 对象没有属性 'pos'