所有的python助手都导致Mypy认为场是可选的
当使用Python All()助手时,我会看到Mypy(版本0.942)认为该字段是可选的,即使All()助手都可以确保所有这些都存在。
对于以下代码段,我看到了
def rate_limit(user_id: int, rate_limit_max: int, rate_limit_since_time: int):
do_something()
def some_func(
user_id: int = None,
rate_limit_max: int = None,
rate_limit_since_time: int = None
):
if all([user_id, rate_limit_max, rate_limit_since_time]):
rate_limit(user_id, rate_limit_max, rate_limit_since_time)
此代码段的Mypy的奇怪行为,我会得到这些行:
error: Argument "user_id" to "rate_limit" has incompatible type "Optional[int]"; expected "int"
When using the python all() helper I am seeing odd behaviour with mypy (version 0.942) where it thinks a field is optional even though the all() helper would make sure all of them exist.
For the following code snippet I am seeing odd behavior from mypy
def rate_limit(user_id: int, rate_limit_max: int, rate_limit_since_time: int):
do_something()
def some_func(
user_id: int = None,
rate_limit_max: int = None,
rate_limit_since_time: int = None
):
if all([user_id, rate_limit_max, rate_limit_since_time]):
rate_limit(user_id, rate_limit_max, rate_limit_since_time)
For this code snippet I get something along these lines:
error: Argument "user_id" to "rate_limit" has incompatible type "Optional[int]"; expected "int"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基于上面提供的文档Juanpa,我可以找到( pep-647 )看起来像Mypy无法弄清楚从All()助手返回的类型是什么。
来自文档
Based on the docs juanpa provided above I was able to find (PEP-647) looks like mypy can't figure out what the type returned from the all() helper would be.
From the docs