-
Notifications
You must be signed in to change notification settings - Fork 37
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
Integration of stack_data #23
base: master
Are you sure you want to change the base?
Conversation
Hey! I need to make time to take a proper look, but to quickly reply to your points at the end:
|
Awesome, I'm glad you're so happy with my proposals.
That is often (probably mostly) the case, although there are plenty of exceptions:
An example of all of these is if you get an We can check for 'normal' cases defined as follows:
In those cases we can hide the extra info by default. But I'm not sure if this would be a good thing.
Yes, but I wasn't clear, I was talking about within this PR. Since I'm not iterating through every token, there is no longer a place to apply |
ranges = [
Range(
node.first_token.start[1],
node.last_token.end[1],
(variable, node),
)
for variable, node in self.frame_info.variables_by_lineno[self.lineno]
] would become something like: ranges = [
Range(
(...)
)
for variable, node in self.frame_info.variables_by_lineno[self.lineno]
] Currently the default is to display at most 6 lines (including the |
I just pushed an update to |
OK, I've created https://github.com/alexmojaki/pure_eval, so There's not that much left for me to implement. I'm very keen to hear your responses to the questions above, particularly the first 3 here. |
Any progress on this ? |
@alexmojaki i'm looking forward to the perks this PR introduces per #23 (comment) |
Hey all! I haven't forgotten about this, I just found it surprisingly difficult to find a free weekend lately. I'll need your patience a bit longer |
Hi @cknd, that's fine, just remember that for now you only need to look at the conversation, not the code changes. I still have plenty more to do. |
Hey, apologies for the delays. To pick up this thread again:
|
If we still specify a number of lines, then I don't understand what's going to change and how the division into pieces (logical blocks) will be used. Can you elaborate, maybe with examples? |
Anyway, in the meantime stack_data and pure_eval have been pretty fully developed. They have complete tests and documentation and are available on PyPI. Hopefully soon they will be integrated into IPython. I suggest you read through the stack_data README. By the way, the new dependencies do not and will not support Python 3.4, which is well past its EOL, so this PR is dropping it. |
Hm, it seems I'm still lacking intuitions how the new stack_data block snipper behaves on real code. I need to play with it some more. Roughly, my thought is: Since the blocks can have varying sizes (1-6 lines with the current default afaik), then for a given maximum nr of blocks to be printed, the resulting printout can vary in length a lot, depending on the nesting structure of the code and the size of the nested blocks. But since the main motive for printing less than the whole scope is to save screen space, any (future) config to limit printing should have a mostly predictable effect on the space that will be used. I'll play with the new snipping mechanism and see how I can map it to this underlying motive, i.e.: Given a certain quantifiable desire to save screen space, how can we select the parts of code most likely to help with debugging. I have a hunch that logical blocks are part of the answer. (random idea that disregards implementation effort: One way to reconcile block selection and a configurable output size might be to treat it as a bin packing problem, packing a number of logical blocks that fits the configured size of printout, prioritized by expected usefulness (starting with the executed line, then outer blocks that explain the control flow to the executed line, and previous occurrences of the variables in the lines printed so far, etc.) /random idea that disregards implementation effort) |
As discussed in #22
This is still very much a WIP, but you can run the demos and see output that looks right until you inspect it more closely. I'm putting some work out early so you can see what's coming and we can start some conversations. To try it out, clone https://github.com/alexmojaki/stack_data and
pip install -e <path to folder>
in your interpreter where you work on stackprinter.A couple of perks you can already observe:
__qualname__
thanks toexecuting
.It shows something like this:
The source line
1 / 0
and its context are absent. This is now fixed.Things I plan on doing soon which should be quite quick and easy:
Changes we need to discuss:
pure_eval
which accepts an AST node and returns a bunch of sub-expressions which can be safely evaluated without triggering any side effects and their corresponding values. This will include for example attributes which are simply present in__dict__
(no properties) or subscriptsa[b]
wherea
has a known type like a list or dict. I think it's dangerous to evaluate arbitrary attributes like you're doing now because this risks mutating the state of the program which could interfere with someone's debugging.better-exceptions
has a similar view - they are currently trying to integrate the display of attributes but only usinggetattr_static
. With this in mind there would no longer be such a thing as UnresolvedAttribute.if
condition is a single piece. Context is measured in numbers of pieces, e.g. the default is to include 3 pieces before and 1 piece after. This may be more than 5 lines total but the advantage is that tracebacks don't truncate statements or other groups of lines that should logically be together. However if you have a very long piece then it may be truncated in the middle to avoid arbitrarily long tracebacks.executing
library. The simplest way is to add a line such asWhile calling: foo()
to each frame. This is probably the only decent option when there's no color. With color, there's the possibility of highlighting the expression similar to what heartrate does. However given that the expression may contain multiple variables with random colors this will probably be hard to do in a way that's reliably readable.