我知道我可以使用“查找用法”来查找调用类中方法的内容。 有没有办法对给定类的所有方法执行此操作? (或者实际上是文件中的所有方法)
用例:我正在尝试重构一个 god 类,它几乎可以肯定是几个类。如果能够看到 god 类方法的子集,与它交互的类使用什么,那就太好了。似乎 PyCharm 已经完成了这方面的艰巨工作,但不允许我扩大规模。
我使用的是 PyCharm 2016.1.2
请您参考如下方法:
这是可能的,但你必须处理抽象,否则 Pycharm 不知道有问题的方法属于你的特定类。又名 - Type Hinting
将找不到在没有类型提示的抽象层中调用该方法的任何实例。
例子:
#The class which has the method you're searching for.
class Inst(object):
def mymethod(self):
return
#not the class your looking for, but it too has a method of the same name.
class SomethingElse(object):
def mymethod(self):
return
#Option 1 -- Assert hinting
def foo(inst):
assert isinstance(inst, Inst)
inst.mymethod()
#Option 2 -- docstring hinting
def bar(inst):
"""
:param inst:
:type inst: Inst
:return:
:rtype:
"""
inst.mymethod()
