Join of actual Class with Type[Class] results in `object`
还没有人认领这个 Issue。
评估
调研方向
Start with the provided Python reproducer and trace mypy's handling of the conditional-expression type join involving the actual Foo class and Type[Foo]. Run the example to confirm the revealed type and call error; done means the expression is inferred as Type[Foo], Foo can be called, and the existing reversed-order and cls or Foo cases remain covered.
由索引模型根据 Issue 内容生成。
描述
This file:
from typing import Type, Optional
class Foo:
pass
def make_foo(cls: Optional[Type[Foo]] = None) -> Foo:
x = Foo if cls is None else cls
reveal_type(x)
return x()
gives the following:
typeofclass.py:10: error: Revealed type is 'builtins.object'
typeofclass.py:11: error: "object" not callable
This example is superficially related to #3487, in that it uses an if/else expression to make mypy perform a type join, but the distinct bug here is that joining Foo (the actual class object) with Type[Foo] should result in Type[Foo], but instead results in object.
This is related to the fact that class objects are typed as callables instead of as Type[Class].
Oddly reversing Foo if cls is None else cls to cls if cls is not None else Foo results in builtin.type instead of object, which is still wrong, but differently wrong.
Using cls or Foo results in Type[Foo].
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- 平均合并
- 1 天 18 小时
- 30 天内合并 PR
- 54
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/mypy 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
-
documentation
难度 2/5 1-3 小时 新手友好度 72/100
-
bug topic-configuration topic-error-reporting
难度 2/5 1-3 小时 新手友好度 68/100
相似的 Issue
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
bancolombia/sentinel#23 ·
-
test md 未关闭CI
难度 2/5 1-3 小时 新手友好度 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
难度 2/5 1-3 小时 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
bug client
难度 2/5 1-3 小时 新手友好度 88/100