title: How to get the function of a change in Python?
body: <p>I am working on a Python script that aims to output the functions in which changes since the last Git commit occurred. For example, if I have the following code already in the most updated Git repo:</p>
  <pre><code>def testFunction():
     print('hello')
  </code></pre>
  <p>And I made the following change that has not yet been pushed to Git:</p>
  <pre><code>def testFunction():
     print('bye')
  </code></pre>
  <p>My script should output the function &quot;testFunction.&quot;</p>
  <p>Is there any existing Python libraries or modules that can accomplish something like this? If not, what approach can I use to accomplish this?</p>
  <p>One approach I was thinking is to first get the line number of the change. For example, if print('hello') is on line 2 and I changed it to print('bye'), then my script should be able to detect the change occurred on line 2. It seems like 'git diff' is able to do something like this since it provides a range of line numbers, but I am not sure if it can provide the exact line number. Then once I have the line number where the change occurred, I may be able to use a module called inspect (docs.python.org/3/library/inspect.html) to get me a list of functions and the line numbers of functions. If the line number of the change is between a certain range of line numbers, then that change is in that function.</p>