Hacker News new | ask | show | jobs
by apurtbapurt 1635 days ago
I maintain some code that rely on Python AST for finding and packaging modules with appropriate class signatures when building customer specific distributions. It works really well most of the time. And, it is a lot easier to maintain than 50+ separate wheel definitions.

The one big drawback is that the AST for even trivial code patterns has had a history of changing between Python versions. This makes it more annoying than usual to support multiple versions at the same time. Luckily 3.9 and 3.10 hasn't brought any changes that impacted my codebase, as far as I've noticed.

1 comments

The only major changes that I'm aware of since python3 has been the change with keyword arguments in 3.6, and the deprecation of Index and introduction of Constant more recently. Those are big changes, but relatively small and maintainable imo. What challenges have you faced?
> the deprecation of Index and introduction of Constant more recently.

The introduction of Constant also deprecated everything it replaced (Str, Num, Bytes, and NameConstant).

There's also the introduction of f-strings (ast'd as JoinedStr), various nodes being duplicated for their async version.

Probably more relevant to automatically discovering signatures would be the addition of positional-only arguments to the `arguments` object.

But messing with the AST is definitely a lot more stable than messing with the bytecode.