This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: stdlib inspect documentation on code.co_names is incorrect
Type: Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Dutcho, docs@python, iritkatriel, slateny
Priority: normal Keywords: easy, patch

Created on 2021-10-16 10:45 by Dutcho, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31456 merged slateny, 2022-02-21 00:47
PR 31645 merged iritkatriel, 2022-03-02 19:26
Messages (3)
msg404068 - (view) Author: (Dutcho) Date: 2021-10-16 10:45
The standard library documentation on module inspect starts with an overview of types and attributes. This overview (in all Python versions) states:
    code.co_names: tuple of names of local variables
    code.co_varnames: tuple of names of arguments and local variables
That suggests the argument names are set(code.co_varnames) - set(code.co_names), which is incorrect.

I think the attribute description should be:
    code.co_names: tuple of names of used global and built-in variables

>>> def f(x): a = 1; print(f, a)
>>> assert f.__code__.co_varnames == ('x', 'a')  # argument and local, in that order
>>> assert set(f.__code__.co_names) == set(('f', 'print'))  # global and built-in (don't care order), not local
msg414383 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-02 19:03
New changeset 3257d49d236e5f3453fe9d2fd8338bcdfe9756b7 by slateny in branch 'main':
bpo-45492: Corrected documentation for co_names in inspect library doc (GH-31456)
https://github.com/python/cpython/commit/3257d49d236e5f3453fe9d2fd8338bcdfe9756b7
msg414384 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2022-03-02 19:37
New changeset eb65e46b9b28103767c115ccf71a97a9f4237d4c by Irit Katriel in branch '3.10':
[3.10] bpo-45492: Corrected documentation for co_names in inspect library doc (GH-31456). (GH-31645)
https://github.com/python/cpython/commit/eb65e46b9b28103767c115ccf71a97a9f4237d4c
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89655
2022-03-02 19:37:56iritkatrielsetstatus: open -> closed
stage: patch review -> resolved
resolution: fixed
versions: - Python 3.9
2022-03-02 19:37:29iritkatrielsetmessages: + msg414384
2022-03-02 19:26:41iritkatrielsetpull_requests: + pull_request29765
2022-03-02 19:03:46iritkatrielsetnosy: + iritkatriel
messages: + msg414383
2022-02-21 00:47:24slatenysetkeywords: + patch
nosy: + slateny

pull_requests: + pull_request29585
stage: patch review
2022-01-14 13:56:49iritkatrielsetkeywords: + easy
versions: - Python 3.6, Python 3.7, Python 3.8
2021-10-16 10:45:28Dutchocreate