I have a big legacy Python method which contains roughly twenty return
statements.
The method should not return None
but it does so. It is repeatable in a simple test case.
Up to now I used a debugger and stepped through the code line by line to find the matching return statement.
But is there an easier way?
Is there a way to raise an Exception as soon as the method returns None?
and Of course I need to see the line containing the return statement.
Example:
def big_method(arg1, some_var):
#.... many returns
if arg1:
return some_var # <------
#... many returns
assert not big_method(True, None) is None
Above is a simple code snippet. The result:
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
Above traceback does not help very much, since I want to see the line inside big_method()
. In the example above I want to see which I marked with <------
.
I use PyCharm, but a pure python or other solution is welcome.
Just for the records. There is a follow-up question which tries to enable this feature in PyCharm: PyCharm: Debugging: r(eturn) Continue execution until the current function returns