title: Debug where method returns None
body: <p>I have a big legacy Python method which contains roughly twenty <code>return</code> statements.</p>
  
  <p>The method should not return <code>None</code> but it does so. It is repeatable in a simple test case.</p>
  
  <p>Up to now I used a debugger and stepped through the code line by line to find the matching return statement.</p>
  
  <p>But is there an easier way?</p>
  
  <p>Is there a way to raise an Exception as soon as the method returns None?</p>
  
  <p>and Of course I need to see the line containing the return statement.</p>
  
  <p>Example:</p>
  
  <pre><code>def big_method(arg1, some_var):
      #.... many returns
      if arg1:
          return some_var # &lt;------
      #... many returns
  
  
  assert not big_method(True, None) is None
  </code></pre>
  
  <p>Above is a simple code snippet. The result:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/modwork_vums_d/src/manyreturns.py", line 8, in &lt;module&gt;
      assert not big_method(True, None) is None
  AssertionError
  </code></pre>
  
  <p>Above traceback does not help very much, since I want to see the line <strong>inside</strong> <code>big_method()</code>. In the example above I want to see which I marked with <code>&lt;------</code>.</p>
  
  <p>I use PyCharm, but a pure python or other solution is welcome.</p>
  
  <p>Just for the records. There is a follow-up question which tries to enable this feature in PyCharm: <a href="https://stackoverflow.com/questions/47887099/pycharm-debugging-return-continue-execution-until-the-current-function-retur">PyCharm: Debugging: r(eturn) Continue execution until the current function returns</a></p>