在 mypy 中针对 PEP 585 引发弃用警告

发布于 2025-01-19 19:52:25 字数 491 浏览 1 评论 0原文

在我正在进行的一个项目中,我们广泛使用类型提示。我们现在正在更新到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文