YAPF 0.17.0 已发布,YAPF 是 Google 开源的一个用来格式化 Python 代码的工具。 目前用于 Python 的格式化程序(如 autopep8 和 pep8ify)都用于删除代码中的 lint 错误。这有很明显的局限性。YAPF 采用了不同的方法,基于 Daniel Jasper 开发的 “clang-format” 。从本质上来说,该算法取走代码并重新排版,以符合样式指南的最佳格式,即便原始代码没有违反样式指南。这个想法也是类似于 Go 编程语言的 gofmt 工具。其最终目标是让 YAPE 所产生的代码可以与程序员所写的代码一样好(前提是程序员遵循样式指南),它取代了一些维护代码的苦差。 更新内容: 新增 Option `NO_SPACES_AROUND_SELECTED_BINARY_OPERATORS` prevents adding spaces around selected binary operators, in accordance with the current style guide. 更改 Adjust blank lines on formatting boundaries when using the `--lines` option. Return 1 if a diff changed the code. This is in line with how GNU diff acts. 修复 Corrected how `DEDENT_CLOSING_BRACKETS` and `COALESCE_BRACKETS` interacted. Fix return value to return a boolean. Correct vim plugin not to clobber edited code if yapf returns an error. Ensured comma-terminated tuples with multiple elements are split onto separate lines. 下载地址: Source code (zip) Source code (tar.gz) YAPF 0.17.0 发布,Python 代码格式化工具下载地址