title: Python get line number of classes from imported module
body: <p>I have been using importlib to get the module from an imported python file and would like to get the line number where each class is defined in the python file.
  For example I have something like this:</p>
  <pre><code>testSpec = importlib.util.spec_from_file_location(&quot;&quot;, old_file)
  testModule = importlib.util.module_from_spec(testSpec)
  testSpec.loader.exec_module(testModule)
  </code></pre>
  <p>Where old_file is a python file (lets call it old.py). Then using the inspect library I can find all of the classes from old.py in this way:</p>
  <pre><code>for name, obj in inspect.getmembers(testModule):
      if inspect.isclass(obj):
          print(name)
  </code></pre>
  <p>This gives me all of the created class names from old.py which is correct. However, what I would like to do is also get the line number where this class appears in old.py. I have tried to add this line in the if statement right after the print statement: <code>print(inspect.getsourcelines(obj))</code></p>
  <p>However, this errors out in this way:</p>
  <pre><code>File &quot;old.py&quot;, line 665, in getfile
  raise TypeError('{!r} is a built-in class'.format(object))
  TypeError: &lt;class '.exampleClassName'&gt; is a built-in class
  </code></pre>
  <p>I am not sure why it considers this user-created class a built-in class, but is there another way that I can just get the line number where this class is defined in old.py? For example if old.py looks like this:</p>
  <pre><code>#test comment line 1
  #test comment line 2
  
  class exampleClassName:
      test = 0
  </code></pre>
  <p>Then when I have the class object exampleClassName I would expect to print out 4 from <code>inspect.getsourcelines(obj)</code> since it is defined on line 4.</p>