Facebook 调查显示类型化 Python 采用率增长,提升代码质量与灵活性

Facebook 2025 年调查显示,开发者对类型化 Python 的采用显著增长,86% 的受访者表示总是或经常使用类型提示,其中 5-10 年经验的开发者采用率最高(89%)。开发者高度评价类型提示带来的可读性提升、更好的 IDE 支持、早期错误检测和代码信心增强。然而挑战依然存在,包括第三方库支持有限、高级功能复杂性、代码冗长和工具碎片化等问题。调查还显示开发者期望获得类似 TypeScript 的功能特性、更好的泛型支持、可选的运行时类型检查以及性能优化。虽然 MyPy 仍是主导的类型检查器,但基于 Rust 的新工具正在获得关注。这些发现凸显了 Python 开发生态的演变,表明通过静态类型实现更健壮和可维护代码库的强劲趋势。




Conducted among over 1,200 respondents, Facebook's 2025 Typed Python Survey highlights how and why Python developers have increasingly adopted the language's type hinting system. The survey also sheds light on what developers value most, as well as their biggest frustrations and wishes.

Overall, 86% of respondents reported they "always" or "often" use type hints in their code, with adoption highest among developers with 5–10 years of Python experience.

While the data shows that type hints have been widely adopted among the surveyed sample, selection bias cannot be ruled out, as developers who use typing may be more likely to respond. Nevertheless, the survey reveals interesting trends among Python developers who use type hints.

The survey results reveal that Python’s type hinting system has become a core part of development for most engineers. [...] We found that adoption of typing is similar across all experience levels, but there are some interesting nuances.

Both junior (0-2 years of experience) and very senior (10+ years of experience)developers use type hints less frequently, at 83% and 80% respectively. The survey authors suggest that junior developers face a steeper learning curve, while senior developers may be working with large, legacy codebases where adopting type hints is more difficult.

Developers cited several benefits from adopting Python’s type system, including better readability and in-code documentation, improved IDE and tooling support, early bug detection, and increased confidence. They also highlighted the value of advanced features such as protocols, generics, and the ability to inspect annotations at runtime.

On the other hand, respondents identified several challenges, including limited type hinting support in third-party libraries, the complexity of advanced features like generics and decorators, and increased verbosity for complex types. Other pain points included tool fragmentation, the lack of runtime enforcement, and difficulty retrofitting legacy code. Respondents also noted that Python's type system appears less expressive than those of other languages, such as TypeScript, and that its rapid evolution means syntax and best practices are constantly changing.

Another interesting set of findings from the survey concerns ways to improve the Python type system. Several suggestions included features borrowed from TypeScript, such as intersection types, mapped and conditional types, utility types (like Pick, Omit, keyof, and typeof), and better structural typing for dictionaries. Other suggestions focused on better support for generics and algebraic data types, including higher-kinded types; optional runtime type enforcement and performance optimization based on type hints; improved handling of patterns like function wrappers and decorators, support for dynamic attributes; and more.

On the tooling front, MyPy remains the preferred type checker with 58% adoption, closely followed by Pyright/Pylance. New Rust-based type checkers like Pyrefly, Ty, and Zuban are gaining traction, being used by over 20% of respondents. Visual Studio Code is the most common IDE, followed by PyCharm and Vim/Neovim.

There is much more in this survey than can be covered here. Be sure to read the original article for the full details.



AI 前线

从混乱到规模化:使用 DLT-META 模板化 Spark 声明式管道

2026-1-10 18:21:43

AI 前线

如何使用 Google Antigravity 构建 AI 驱动的 Flutter 应用:实践教程

2026-1-10 18:21:47

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索