Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.0k views
in Technique[技术] by (71.8m points)

abstract syntax tree - Force Python ast to emit lines no longer than length

I've written a library that works at the ast level. Sometimes the generated output goes over the linter line length limit.

"foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz"

How do I generate this kind of code instead?

"foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz_"
"foo_bar_can_haz_foo_bar_can_haz_foo_bar_can_haz"

(also happy with the and parenthesised variants)

The only thing I can think of doing—retaining support for 3.6, 3.7, 3.8, 3.9, and 3.10a4—is to contribute to both astor and the builtin ast.unparse


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I ended up adding word-wrap support directly to my code-generation: https://github.com/SamuelMarks/doctrans/commit/6147b21e168b66623aa1be95cb38b1969daa5147


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...