在 mypy 中针对 PEP 585 引发弃用警告
在我正在进行的一个项目中,我们广泛使用类型提示。我们现在正在更新到 python 3.9,其扩展的类型提示功能在 PEP 585。在测试更改时我遇到了一个有趣的问题。
PEP 585 规定:
不推荐从输入中导入这些内容。由于 PEP 563 以及尽量减少输入对运行时影响的目的,此弃用不会生成 DeprecationWarnings。相反,当被检查程序的目标版本被标记为 Python 3.9 或更高版本时,类型检查器可能会警告此类已弃用的用法。建议在项目范围内消除这些警告。
但是在包含旧打字方式的代码上运行 mypy(例如:tp.List[str]
而不是 list[str]
)mypy 不会引发弃用警告或任何类型的警告就此问题发出警告。
我缺少什么?
In a project I'm working on we're extensively using type hinting. And we're now updating to python 3.9, with it's expanded type hinting functionality defined in PEP 585. And testing the change I ran into an interesting issue.
PEP 585 states:
Importing those from typing is deprecated. Due to PEP 563 and the intention to minimize the runtime impact of typing, this deprecation will not generate DeprecationWarnings. Instead, type checkers may warn about such deprecated usage when the target version of the checked program is signalled to be Python 3.9 or newer. It’s recommended to allow for those warnings to be silenced on a project-wide basis.
But running mypy on code containing the old typing way (for example: tp.List[str]
instead of list[str]
) mypy raises no deprecation warning, or any kind of warning for that matter.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论