Force Python ast to emit lines no longer than $length

Samuel Marks samuelmarks at gmail.com
Tue Jan 19 22:05:15 EST 2021


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) [cross-posted:
stackoverflow.com/q/65800797]

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…


More information about the Python-list mailing list