Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code Fragment mode in Pycharm 3 debugging returns None always

When in debug mode in Pycharm, the Evaluate Expression -> Code Fragment tool doesn't seem to be able to assign and display a variable in one go. The only case that seems to be evaluated correctly is when the first line is a constant value.

eg.

10

results as expected in

result = {int} 10

but when trying to obtain the same result with:

c = 10
c

the output is

result = {NoneType} None

However, if I hover over each variable in fragment window, the values are shown as a popup.

like image 803
Vaibhav Mishra Avatar asked Nov 21 '13 07:11

Vaibhav Mishra


People also ask

Why does PyCharm not Debug?

Faced the same issue and even tried different PyCharm versions without success. In the end the reason for debugging console not working was that somewhere in the repo sys. out and sys. stderr were being overwritten.

How do you set a breakpoint in PyCharm?

Set breakpointsClick the gutter at the executable line of code where you want to set the breakpoint. Alternatively, place the caret at the line and press Ctrl+F8 .


1 Answers

Edits to sum up the comments (thanks Vaibhav Mishra):

Unfortunately, this seems to be the default behavior: (won't fix bug)

My understanding of this feature:

Although Pycharm will display a None result when evaluating multiple lines, they are all executed in the context of the currently selected stack frame. One of the consequences being the update of the namespace. Subsequently using single-line evaluations in the same context (or mouse hover) will display the expected values.

Two potential usages:

  1. The Evaluate Code Fragment dialog is automatically prompted when evaluating multiple lines from the editor: Select a block | Evaluate Expression (Alt+F8). May be useful to tweak a couple of lines and run evaluation in one go.
  2. As an alternative to the Debug Command Line, the code fragment mode supports loops and if/else. Although the inspection seems a bit tipsy (mistakenly unresolved variables), it can be ignored, and the editing assistance provided there can be put to good use.
like image 110
Arnaud P Avatar answered Sep 18 '22 09:09

Arnaud P