-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the library executing
#33
Conversation
Awesome work. Will dig into this PR shortly! |
What breaks with Python 3.4?
Yep. Same behavior manually detected and accounted for by icecream in Could still detect and do the same with extraction.py.
Displayed source should be normalized. This ic( a + b ) is best printed as ic| a + b: 1 not ic| a + b : 1 Source code alignment and spacing, which may be arbitrary, shouldn't affect |
There are some tests in asttokens that fail in 3.4, I don't remember which. I'm guessing it'll work most of the time but sometimes may silently do the wrong thing. If I write: ic(foo(
bar=thing,
baz=qux([
x + y
for x in range(n)
for y in range(x)
])
)) and I see
Your example with In any case, like I said, it's up to you to figure out how to make whitespace and parentheses look how you want. |
Huge thank you @alexmojaki for all your hard work to merge executing into icecream. |
Hi!
I wanted to integrate this library's functionality into my own project, so I looked into how it worked, and discovered that in many cases it didn't. Here's a quick script showing various cases in which it fails. They all work after this PR.
I tried to fix the algorithm, but slowly discovered more and more that it was fundamentally broken. In the end all that's left is the general idea of analysing the bytecode and using
frame.f_lasti
. But I want to emphasise that even this was a big leap, and what you accomplished was very impressive. I didn't know that this was a solvable problem. Your code inspired me and set me in the right direction to create something very cool with broad potential applications.The new algorithm now lives in a new general purpose little package I've created called
executing
. It finds the AST node corresponding to theic()
call. Translating that into source code is done withasttokens
, which is the best method I know of. Unfortunately it comes with a couple of small problems:ic((1, 2))
just gives1, 2
as the source, which is causing some failures. If you want to fix this, take a look at Include parentheses around expressions in token range gristlabs/asttokens#11There's also some failures because
collapseWhitespaceBetweenTokens
doesn't seem to be doing what the name suggests. Personally I don't think the displayed source code should be modified anyway. If you still want to do that, you'll have to figure out how.Some other perks:
icecream.ic()
works. In factic
can be the result of any expression.