gue*_*tli 10 python debugging pycharm
我有一个很大的遗留Python方法,其中包含大约20个return语句.
该方法不应该返回,None但它会这样做.它在一个简单的测试用例中是可重复的.
到目前为止,我使用了一个调试器并逐行遍历代码以找到匹配的return语句.
但是有更简单的方法吗?
一旦方法返回None,有没有办法提出异常?
当然我需要看到包含return语句的行.
例:
def big_method(arg1, some_var):
#.... many returns
if arg1:
return some_var # <------
#... many returns
assert not big_method(True, None) is None
Run Code Online (Sandbox Code Playgroud)
上面是一个简单的代码片段.结果:
Traceback (most recent call last):
File "/home/modwork_vums_d/src/manyreturns.py", line 8, in <module>
assert not big_method(True, None) is None
AssertionError
Run Code Online (Sandbox Code Playgroud)
上面的追溯并没有多大帮助,因为我想看到内线 big_method().在上面的例子中,我想看看我标记的是哪个<------.
我使用PyCharm,但欢迎使用纯Python或其他解决方案.
仅供记录.有一个后续问题试图在PyCharm中启用此功能:PyCharm:调试:r(eturn)继续执行,直到当前函数返回
geo*_*xsh 12
pdb有一个r(eturn)命令来满足这个需求:
r(eturn)继续执行,直到当前函数返回.
例:
> /Users/georgexsh/wasteland/tmp/app.py(6)<module>()
-> assert not big_method(True, None) is None
(Pdb) s
--Call--
> /Users/georgexsh/wasteland/tmp/app.py(1)big_method()
-> def big_method(arg1, some_var):
(Pdb) r
--Return--
> /Users/georgexsh/wasteland/tmp/app.py(3)big_method()->None
-> return some_var
Run Code Online (Sandbox Code Playgroud)
在pdb doc中查看更多细节.
| 归档时间: |
|
| 查看次数: |
353 次 |
| 最近记录: |