Find where Python function is called in PyCharm

您所在的位置:网站首页 pycharm中的循环语句在哪 Find where Python function is called in PyCharm

Find where Python function is called in PyCharm

2023-03-23 20:26| 来源: 网络整理| 查看: 265

Answer a question

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?

Answers

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.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3