Something like?
a = maybe('a[0].attr(arg) or b[0]')
Could get AST, transform it based on rules and evaluate with locals()
. Would do short-circuiting and would be very flexible.
Would be nice to have a concept of code-strings, where one could just prepend c
which does nothing, except signals IDEs to do syntax highlighting. Such DSLs would be much more attractive.
Context manager would stay within Python without inner DSL, which I like - no issues with syntax highlighting and feels more natural from users perspective.
But not sure how to do short-circuiting for such. Would be interesting to try prototyping to see what is possible.