paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Hard to Read and Understand Pythonic Idioms? DeIdiom and Explain Them in Non-Idiomatic Equivalent Code

难以阅读和理解 Pythonic 惯用法?用 DeIdiom 将其转换为非惯用等价代码并加以解释
ICSE Proceedings of the IEEE/ACM 46th International Conference on Software Engineering2024匹配度 2/10 · 论文关注 Pythonic 惯用法的自动转换与可读性提升,属于编程语言/开发者工具方向,但不涉及 LLM/Agent、面向 ML/Agentic 程序的静态分析、浮点程序分析或贝叶斯程序分析,与用户研究画像的核心问题交集很少。引用 7 inbox
Zejun Zhang, Zhenchang Xing, Dehai Zhao, Qinghua Lu, Xiwei Xu, Liming Zhu
crossref: 2026-09-12

AI 速览

一句话:提出 DeIdiom,将九类 Pythonic 惯用法自动转换为等价非惯用代码,以提升可读性并辅助理解。

Python 社区提倡用 Pythonic 惯用法简洁高效地表达意图,但对 Stack Overflow 上 154 个问题的分析显示用户理解这些惯用法存在多种困难,7,577 个 GitHub 项目又表明其广泛使用。惯用法不仅词法简洁,还会创建变量和函数,难以直接映射回非惯用代码,并可能带来冗余、缺陷和性能下降。作者开发 DeIdiom,自动将惯用代码转换为等价非惯用代码。针对九类惯用法(列表/集合/字典推导、链式比较、真值测试、循环 else、多重赋值、for 多目标、星号等)的 7,572 个实例,测试与审查显示高准确率;20 人用户研究表明生成的解释性非惯用代码能帮助用户正确高效地理解惯用法,并更积极地评价它们。

问题
Pythonic 惯用法虽简洁高效,却给 Python 用户理解并映射回非惯用代码带来困难,还可能引发代码冗余、缺陷和性能下降。
方法
通过 Stack Overflow 问题与 GitHub 项目分析惯用法的使用与理解挑战,并实现 DeIdiom 自动转换工具,将惯用代码改写为等价的非惯用解释性代码。
评估
在九类惯用法的 7,572 个实例上测试审查以评估转换准确率,并通过 20 人用户研究验证生成代码对理解惯用法的帮助。
原文摘要(Abstract)

The Python community strives to design pythonic idioms so that Python users can achieve their intent in a more concise and efficient way. According to our analysis of 154 questions about challenges of understanding pythonic idioms on Stack Overflow, we find that Python users face various challenges in comprehending pythonic idioms. And the usage of pythonic idioms in 7,577 GitHub projects reveals the prevalence of pythonic idioms. By using a statistical sampling method, we find pythonic idioms result in not only lexical conciseness but also the creation of variables and functions, which indicates it is not straightforward to map back to non-idiomatic code. And usage of pythonic idioms may even cause potential negative effects such as code redundancy, bugs and performance degradation. To alleviate such readability issues and negative effects, we develop a transforming tool, DeIdiom, to automatically transform idiomatic code into equivalent non-idiomatic code. We test and review over 7,572 idiomatic code instances of nine pythonic idioms (list/set/dict-comprehension, chain-comparison, truth-value-test, loop-else, assign-multi-targets, for-multi-targets, star), the result shows the high accuracy of DeIdiom. Our user study with 20 participants demonstrates that explanatory non-idiomatic code generated by DeIdiom is useful for Python users to understand pythonic idioms correctly and efficiently, and leads to a more positive appreciation of pythonic idioms.

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@inproceedings{paperbot11287,
  title = {Hard to Read and Understand Pythonic Idioms? DeIdiom and Explain Them in Non-Idiomatic Equivalent Code},
  author = {Zejun Zhang and Zhenchang Xing and Dehai Zhao and Qinghua Lu and Xiwei Xu and Liming Zhu},
  booktitle = {ICSE},
  year = {2024},
  doi = {10.1145/3597503.3639101}
}