[Python-ideas] Dictionary initialization to capture syntax and value (was Re: Debugging: some problems and possible solutions)

Anders Hovmöller boxed at killingar.net
Wed Oct 3 19:24:17 EDT 2018

>>>    {=(1 + bar), }
>>> is equivalent to
>>>    {'1 + bar': 1 + bar, }
> What is so special about dicts that this only works there?
> If we're going to have syntax to capture the source (and AST) of an 
> expression, it ought to work everywhere. And it ought to be callable, 
> without having to call eval() on the source, which is slow.

So... what are you thinking? We store the AST in a way that can be inspected by the inspect module? Seems a bit vague how the API would look. Would you look at the stack and traverse it and the frames contain detailed information on where a function call originated in the AST? 

That's how I interpret the "works everywhere" idea. It seems pretty complex! I hope you have a simpler idea. 

On a related note: any access of the AST will be annoying to use if the standard library doesn't have an unparse feature, and if it does, it'll be slightly annoying if all formatting and comments are thrown away like the current AST does. 

/ Anders 

More information about the Python-ideas mailing list