Hello Python 3.15, goodbye 3.10, and now I can use 3.11
Hello Python 3.15, goodbye 3.10, and now I can use 3.11
Python 3.15来了!这是Python 3.15的必备更新指南,今年由3.14和3.15版本发布负责人Hugo van Kemenade整理。作为一名构建可在所有支持的Python版本中运行的开源软件的人,我可以说,我将告别Python 3.10,并开始拥抱Python 3.11的新特性。首先,一些Python 3.15的亮点。显式延迟导入我最兴奋的是来自PEP 810的显式延迟导入功能。这允许你像这样导入模块:lazy import json lazy from pathlib import Path 模块将在后续代码中首次使用这些符号时被导入。我的LLM命令行工具实现了插件。我不得不在插件作者文档中推荐手动延迟导入,因为仅仅安装使用了像sentence_transformers这样的重型依赖的插件,会使每次调用llm命令都增加数秒。延迟导入直接解决了这个启动成本。推导式中的解包新语法[*sublist for sublist in lists]非常棒。这里有一个从文档中摘录的示例:lists = [[1, 2], [3, 4], [5]] [*L for L in lists] # [1, 2, 3, 4, 5] # 等价于[x for L in lists for x in L]
Python 3.15 is here ! Here's the essential What's new in Python 3.15 guide, this year curated by 3.14 and 3.15 release manager Hugo van Kemenade. As someone who builds open source software that works in every supported Python version, I get to say goodbye to Python 3.10 and start embracing features from Python 3.11. First, some highlights from Python 3.15. Explicit lazy imports I'm most excited about Explicit lazy imports from PEP 810 . These let you import modules like so: lazy import json lazy from pathlib import Path The module will then be imported the first time those symbols are used in the code that follows. My LLM CLI tool implements plugins. I had to recommend manual lazy imports in the plugin author documentation, because simply installing plugins that used heavy dependencies such as sentence_transformers could add multiple seconds to every invocation of the llm command. Lazy imports directly address this startup cost. Unpacking in comprehensions The new [*sublist for sublist in lists] unpacking syntax is neat. Here's an illustration lifted from the documentation : lists = [[ 1 , 2 ], [ 3 , 4 ], [ 5 ]] [ * L for L in lists ] # [1, 2, 3, 4, 5] # equivalent to [x for L in l
应来源方要求,这里只提供摘要与原文入口。完整内容请阅读原文。
来源:Simon Willison · simonwillison.net