Pycharm find where the python function is called

Is there a way for PyCharm to show where this Python function is called from?

Currently, I rely only on finding the name of the function in the project, and this often works fine, but if the function name is vague, there are a lot of wrong calls. I am wondering if any function is missing somewhere, for example. perhaps the search results can be further narrowed down to show only where the modules import the module I'm looking for?

+8
python pycharm
source share
2 answers

In PyCharm, you can select a function and press Alt + Shift + F7 to start a search for usage. It is also available in the "Edit β†’ Find β†’ Find Usage" section. It looks more intelligent than text search.

Using static analysis to find where a function is called from is generally difficult in Python because it uses dynamic binding and has a lot of introspection, so it’s very easy to get false positives to skip using. In the case of modular functions, I find it a good solution to always use module.function to call the function and never do from module import function . That way you can do a text search for "module.function". Python style guides usually recommend importing functions, etc. So I think this is generally accepted good practice.

Finding method calls is, of course, much more difficult. One of the things that I like about developing in Java and C # is the ability to find all the ways to use the method through static analysis.

+10
source share

Press the Ctrl key and simultaneously hover over the function title. The function name should be highlighted. Click on the function name to get a list of all instances where the function is being called.

If you press the Ctrl key and simultaneously hover over the function call, then the function name will be highlighted and clicking on it will lead to the definition of the function.

+2
source share

All Articles