python - 使 flake8 检测 Python 类型错误
问题描述
通过FastAPI 文档,它看起来像以下函数
def get_name_with_age(name: str, age: int):
name_with_age = name + " is this old: " + age
return name_with_age
应该通过 Python linter(mypy,在示例中)在 VSCode 中触发错误消息
我已经在使用 flake8 但它没有检测到此类错误。有没有办法让 flake8 表现得像那样?
解决方案
对不起,但这看起来不可能。
在 中mypy
,此功能由 提供"check_untyped_defs=true"
。我们可以在 settings.json 中使用此配置禁用它:
"python.linting.mypyArgs": [
"--follow-imports=silent",
"--ignore-missing-imports",
"--show-column-numbers",
"--no-pretty",
"check_untyped_defs=false" //this line
],
而从 flake8 的官方文档中,它只禁用了这些功能:
By default, Flake8 ignores E121, E123, E126, E226, E24, and E704.
但是,尽管您同时启用了它们,但 flake8 仍然无法正常工作。
所以,看起来 flake8 没有这个功能。
推荐阅读
- konvajs - React+Konva:如何用上传的图像填充PatternImage?
- git - 从 git 中删除不在我的仓库中的文件
- javascript - 我需要从网站中选择元素“x”,但网站加载元素“x”太慢
- ruby-on-rails - 带有句点或特殊字符的 Ruby on Rails 路由
- scope - perl6 subs 真的是词法范围还是有额外的?
- arrays - Excel 中的匹配文本
- android - 应用程序如何在没有服务器的情况下代表用户访问 OAuth 服务(例如 Dropbox)?
- java - 价值回报方法JPQL的最佳实践
- excel - 如何按行对数据进行分组?
- java - 如何创建一个创建对列表的引用的对象?