python - 为什么 mypy 在使用 TypedDict 别名时抱怨“对象”不可调用
问题描述
我有文件名为debug.py
:
from typing import TypedDict
class T(TypedDict):
a: int
Q = T
x = Q(a=1)
当我跑步时
mypy debug.py
我懂了
debug.py:9: error: "object" not callable
Found 1 error in 1 file (checked 1 source file)
如果我替换x = Q(a=1)
为x = T(a=1)
,那么抱怨就会消失。
使用reveal_type
节目
debug.py:9: note: Revealed type is 'builtins.object'
debug.py:10: note: Revealed type is 'def () -> debug.T'
为什么不Q
一样T
?
解决方案
推荐阅读
- angular - 如何在角度 7 中关闭另一个组件的模态?
- netlogo - 根据海龟自己的变量建立链接
- linux-kernel - 从 PID 获取可执行文件名(task_struct 中的 comm)
- sql - 我有一个包含错误的查询。他们在哪?
- python - 如何在 Windows 上使用 python3 执行交互式 .exe 命令
- email - 为 Mailjet 创建新联系人并添加到现有列表
- python - 与 Qt/PyQt 中的 KeyPress 事件相比,如何加快 QPushButton 的按下信号的延迟?
- flutter - 在有状态小部件外部调用方法以使用颤振 Bloc 更新 UI
- python - 提高列表创建的性能
- excel - 自动过滤仅返回两个数字之间的数据,但返回空白