`and` fails to refine `Optional[T]`
还没有人认领这个 Issue。
评估
调研方向
从 optional_refine_and.py 中的复现程序开始,并将其行为与 optional_refine_or.py 中失败的对偶案例进行比较。针对这些示例运行静态编译器,以检查报告的类型细化结果。完成的标准是 and 程序被接受,而 or 程序仍然拒绝将 None 传递给 expect_int。
由索引模型根据 Issue 内容生成。
描述
a4a71ae
2021-12-29
What program did you run?
# optional_refine_and.py
# This should pass.
# This should terminate.
from typing import Optional
def expect_int(i: int) -> None:
return
def f(x: Optional[int]) -> None:
return x and expect_int(x)
assert f(None) is None
assert f(42) is None
What happened?
return x and expect_int(x)
^
compiler.errors.TypedSyntaxError: return type must be None, not Optional[int]
What should have happened?
The program should be accepted by the type checker.
Note that a dual test fails as expected.
[root@0fcdc5077884 vol]# cat Playground/conformance_suite/optional_refine_or.py
# optional_refine_or.py
# This should fail.
from typing import Optional
def expect_int(i: int) -> int:
return 42
def f(x: Optional[int]) -> int:
return x or expect_int(x)
[root@0fcdc5077884 vol]# ./python -m compiler --static Playground/conformance_suite/optional_refine_or.py
Traceback (most recent call last):
....
File "Playground/conformance_suite/optional_refine_or.py", line 10
return x or expect_int(x)
^
compiler.errors.TypedSyntaxError: type mismatch: None received for positional arg 'i', expected int
[root@0fcdc5077884 vol]#
- 主要语言
- Python
- 星标
- 3.8k
- 派生
- 139
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
facebookincubator/MetaPython 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 35/100
facebookincubator/MetaPython#147 ·
-
难度 4/5 3-5 天 新手友好度 45/100
facebookincubator/MetaPython#146 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
facebookincubator/MetaPython#145 · 4 条评论 ·
-
难度 3/5 1-2 天 新手友好度 30/100
facebookincubator/MetaPython#144 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 20/100
facebookincubator/MetaPython#129 · 2 条评论 ·
查看 facebookincubator/MetaPython 的全部 Issue
相似的 Issue
-
Device Details tables: FS/SF columns contradict each other (nfet_01v8 Vt row, pfet_01v8 Idsat row)未关闭
难度 2/5 1-3 小时 新手友好度 75/100
google/skywater-pdk#450 ·
-
Drained trajectory arrays are overwritten when the sequence buffer is reused可能已有人在做 @sylvesterkaczmarek 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
google-deepmind/bsuite#56 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
LearningCircuit/local-deep-research#7206 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
chingu-voyages/V62-tier3-team-33#285 ·
维护者通常 1 天内回复
-
Proxy drops log notifications from backends that don't send FastMCP's msg/extra dict可能已有人在做 @asasemahmed 今天认领。 未关闭bug server
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复