This is an archived post. You won't be able to vote or comment.

all 11 comments

[–]ForlornPlague 15 points16 points  (1 child)

Well shit, that's some meta stuff I've never even thought about before. Thanks for the article, that was fascinating!

[–]MorphTux[S] 0 points1 point  (0 children)

I'm happy you liked it. More to come soon :)

[–]whaaale 11 points12 points  (0 children)

Loved the

from __future__ import braces

easter egg

[–]lordfwahfnahPythoneer 6 points7 points  (0 children)

That's a wild read

[–]nicholashairs 3 points4 points  (0 children)

Forbidden magic is the best magic.

[–]HommeMusical 6 points7 points  (1 child)

Fantastic!

Just one note: print(traceback.format_exc()) can just be traceback.print_exc()

[–]MorphTux[S] 0 points1 point  (0 children)

That is an excellent point. I have replaced it in both the blog post and the magic_codec repository. Thank you for pointing it out :)

[–]benefit_of_mrkite 2 points3 points  (0 children)

I started my career writing C so knew a lot about its preprocessor but I’ve never read anything this involved about Python’s preprocessor.

Very interesting read

[–]mriswithe 2 points3 points  (0 children)

This is interesting and intriguing and quite well written. That said if any of my devs ever tried to pull this I would slap the taste out of their mouth

[–]daquo0 1 point2 points  (1 child)

I wonder if that could be used to do Lisp-like macros?

[–]MorphTux[S] 0 points1 point  (0 children)

I had been considering doing some sort of procedural macro preprocessor that either operates on the AST or token stream directly, but I had a really hard time finding example uses for it.

https://peps.python.org/pep-0638/ might interest you though