title: What is co_names?
body: <p>The <a href="https://docs.python.org/3.6/library/inspect.html#types-and-members" rel="nofollow noreferrer">description</a> for <code>co_names</code> in the inspect module reads:</p>
  <blockquote>
  <p>tuple of names of local variables</p>
  </blockquote>
  <p>However in practice it appears that <code>co_names</code> is a tuple of global variable names while <code>co_varnames</code> is a tuple of local variable names (and argument names). For example:</p>
  <pre><code>a = 1
  
  def f(b):
      c = a + b
  
  print(f.__code__.co_varnames)  # prints ('b', 'c')
  print(f.__code__.co_names)     # prints ('a',)
  </code></pre>
  <p>Furthermore in the docs for the <code>dis</code> module many instruction descriptions imply that <code>co_names</code> contains names of global variables. For example the <code>LOAD_GLOBAL</code> <a href="https://docs.python.org/3.6/library/dis.html#opcode-LOAD_GLOBAL" rel="nofollow noreferrer">description</a> reads:</p>
  <blockquote>
  <p>Loads the global named co_names[namei] onto the stack.</p>
  </blockquote>
  <p>Am I misunderstanding something here? Does <code>co_names</code> really contain &quot;names of local variables&quot;?</p>
  <h2><strong>Edit 07/17/2017</strong></h2>
  <p>As mentioned in the comments/answers this appears to be a documentation error. Bug issue filed <a href="http://bugs.python.org/issue30951" rel="nofollow noreferrer">here</a>.</p>
  <h2><strong>Edit 07/22/2017</strong></h2>
  <p><a href="https://github.com/python/cpython/pull/2743" rel="nofollow noreferrer">Pull request</a> to fix this documentation error approved and waiting to be merged.</p>
  <h2><strong>Edit 06/06/2022</strong></h2>
  <p><a href="https://github.com/python/cpython/pull/2743" rel="nofollow noreferrer">Pull request</a> was merged 09/24/2021.</p>