open the source code of a function during debugging

I recently started switching from MATLAB to Python. I'm using PyCharm 2021.2 (Community edition). I'm trying to understand an open-source project written by someone else. Usually in MATLAB, I achieve this by running the script in the debugging mode, and run/read through the code. 

Under the debugging mode in PyCharm, I found that is a function is imported as a built-in function/method, sometimes I can't "step in" to that function. For example, I have these lines of code:

from ThisModule import function1, function2

a = 1
b = 2
c = function1(a, b)

Note that "ThisModule" here is not in the current project, it is a library written and stored in other locations on my local computer, but can be read by the interpreter as I put it on the path. I have two questions (1) I found that in this case, under the debugging mode, at the last line of the code, when I try to "Step-In" the "function1", PyCharm does not open its source code in a new tab in the editor. Instead, it just execute this line (step over) without letting me look into what happens in "function1". (2) Another question, is whether there is a way to open the source code (e.g., from command in Python console) of "function1" in this example. For example, in MATLAB, if I want to take a look at the source code of function1, I can just do "edit function1" or "open function1" in MATLAB's command window. I tried loading inspect module and using inspect.getfile(function1) as recommended by some people when I searched about this online, but kept running into errors. 

Comment actions Permalink
Official comment

Hi, let me try to answer:

1. Please check under [Preferences | Build, Execution, Deployment | Debugger | Stepping], make sure you have "Do not step into library scripts" disabled.

2. Does go to declaration work on this function?

If the external function is not resolved, make sure the external sources are added in project structure settings as content roots.

Comment actions Permalink

I had set "Do not step into library scripts" disabled. The declaration does not work on this function. 
I just noticed that the function I've been trying to "step into" is a function written in a pyx script, instead of a py script. I think that is what causing the problem?


Please sign in to leave a comment.