首页 > 解决方案 > 为什么 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

标签: pythonmypy

解决方案


推荐阅读