Is there a way for PyCharm to show where a given Python function is called from?
I currently rely on simply searching for the function name across the project and this often works fine, but if a function name is vague there are a lot of incorrect hits. I'm wondering if I'm missing a feature somewhere, e.g. perhaps the search results could be further narrowed down to only show where modules import the module I'm searching from?
Type Info In PyCharm, you can identify the type of an expression in the following way: Place the caret at the necessary code element and press Ctrl+Shift+P (or select View | Type Info from the main menu).
Press Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter. Expand the list of the available interpreters and click the Show All link.
From the main menu, choose Edit | Find Usages | Find Usages in File, or press Ctrl+F7 . The encountered usage is highlighted in the editor.
In PyCharm you can select a function and press Alt+Shift+F7 to run a usage search. It's also available under "Edit → Find → Find Usages". It looks like it's more intelligent than a text search.
Using static analysis to find where a function is called from is difficult in general in Python because it uses dynamic binding and has a lot of introspection so it's very easy to get false positives miss usages. In the case of module-level functions I think a good solution is to always use module.function
to call the function and never do a from module import function
. That way you can do a text search for 'module.function'. Python style guides generally recommend that you import functions etc. in this way so I think this is generally accepted good practice.
Finding method calls is of course much harder. One of the things I like about developing in Java and C# is being able to find all usages of a method by static analysis.
Press the Ctrl key and simultaneously hover your mouse over the function header.The function name should get highlighted.Click on the function name to get a list of all instances where the function is called.
If you press the Ctrl key and simultaneously hover your mouse over a function call, then the function name will be highlighted and clicking on it will take you to the function definition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With