Not reporting any error when function returns bool type while expecting str type
还没有人认领这个 Issue。
评估
调研方向
使用 mypy 0.782、Python 3.7.7 以及列出的 --strict-equality 和 --ignore-missing-imports 选项复现报告中的函数,然后将诊断信息与预期的返回类型错误进行比较。跟踪返回表达式和未知类型的类型检查路径;当行为得到修正,或通过回归测试得到清晰记录时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Hi
I noticed a situation where I wasn't getting a type error from mypy when I would have expected to get one.
Below is the code I have. I purposefully set the return type to str because I wanted to see a mypy error, and specifically I expected the error to be that I had set the wrong return type (e.g. as the code is doing a comparison, which will thus return a bool type, I expected mypy to say the return type should be of type bool):
def is_dev() -> str:
return settings.get("environment") == "dev"
In that code snippet you'll see settings.get(...), which is a function that returns a string, and we compare that string against another string.
Note: as
settings.getis custom code, mypy knows nothing about what type is being returned.
My hypothesis is that because my specific example uses code that mypy can't identify the type for (i.e. settings.get()), mypy just goes ahead and ignores any other possible type check errors (such as me specifying the return type as str).
If that's expected of mypy then fine, but it just confused me.
I'm using mypy version 0.782 and Python version 3.7.7.
I'm running mypy in two places:
- vim integration (e.g.
mypy --ignore-missing-imports --strict-equality) - tox (e.g.
mypy --ignore-missing-imports --package foo)
Note: I've tried also changing to
--no-strict-equalityand it makes no difference.
Thank you for any guidance you can give me.
- 主要语言
- 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
-
bug
难度 2/5 1-3 小时 新手友好度 86/100
zostera/django-bootstrap4#894 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
use-agent-os/agent-os#3276 ·
-
难度 2/5 1-3 小时 新手友好度 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
难度 2/5 1-3 小时 新手友好度 88/100
NousResearch/hermes-agent#117848 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
zilliztech/memsearch#759 ·