fosstodon.org is one of the many independent Mastodon servers you can use to participate in the fediverse.
Fosstodon is an invite only Mastodon instance that is open to those who are interested in technology; particularly free & open source software. If you wish to join, contact us for an invite.

Administered by:

Server stats:

9.9K
active users

#libcst

0 posts0 participants0 posts today

Just rewriting #jinja python code generator to #libCST . So far it takes more code to do the same but it's much simpler to do the hard stuff, especially when there's a lot of conditionals.

Take annotated class field: can be generic or not, can have annotated metadata or not. Annotated metadata may be name (class or function), generic or not, or a call, and so on.

A big nuisance of libCST is indentation - it belongs to the previous node, even though we tend to think as part of the next one. For an indented language it's rather weird design decision.

I wrote a blog post about using #libcst to transform #python code that uses assert to use if ...: raise instead and wrote up a blog post about it, especially since I initially ran into a weird error without any clear instructions on how to resolve it: emergent.unpythonic.net/016716

Multiple #circuitpython libraries use this assert pattern which is a problem if the library is mpy-compiled with optimization enabled. Now there's a quick tool that can just transform all asserts to potential RuntimeErrors. But also I just wanted to learn about transforming and re-writing Python modules for myself.

emergent.unpythonic.netA quick example of transforming Python with libcst

Listening to the latest @pythonbytes episode and damn, hearing that @brianokken hadn't heard of #LibCST makes me think I should have brought that along for my own guest appearance in that show after all 😅

I didn't because the topic search said it had been covered in episode 179 by Guido himself 😬

Have found it quite helpful though to write some custom checks and mods to use with precommit on #OctoPrint, has made some cleanup a LOT faster together with #pyupgrade.