Title: Documentation error in inspect module
Type: Stage: patch review
Components: Documentation Versions: Python 3.9, Python 3.8
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, jalexvig, laike9m, marco.buttu, serhiy.storchaka, utkarsh2102, xmorel
Priority: normal Keywords: patch

Created on 2017-07-17 17:29 by jalexvig, last changed 2020-06-25 12:09 by xmorel.

Pull Requests
URL Status Linked Edit
PR 2742 closed jalexvig, 2017-07-17 19:01
PR 2743 open jalexvig, 2017-07-17 19:38
PR 10668 closed utkarsh2102, 2018-11-22 22:12
Messages (5)
msg298545 - (view) Author: Alex (jalexvig) * Date: 2017-07-17 17:29
The documentation for co_names in the inspect module is:

"tuple of names of local variables"

Local variable names are however in co_varnames while co_names contains global variable names. This description should read:

"tuple of names of global variables"

Relevant StackOverflow post here:
msg298644 - (view) Author: Marco Buttu (marco.buttu) * Date: 2017-07-19 08:49
Or maybe: "tuple of names of global variables used in the bytecode"
msg330300 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-11-23 08:58
co_names contains not only names of global variables. It contains also local names in the class scope, attribute names, names of imported modules, etc.
msg334563 - (view) Author: Utkarsh Gupta (utkarsh2102) * Date: 2019-01-30 14:54
Serhiy: What change d'you possibly suggest then?
msg372358 - (view) Author: Xavier Morel (xmorel) * Date: 2020-06-25 12:09
Maybe something along the lines of "names other than arguments and function locals", or "names of the symbols used in the code object, other than arguments and function locals"? This is still slightly confusing because in the case of an import the name is present in both mappings, but less so than the outright lie of the current version.

Serhiy, is there a way to access the class's code object from Python? Also does that mean varnames is not used by class code objects despite it stating unambiguously that it stores locals?
Date User Action Args
2020-06-25 12:09:04xmorelsetnosy: + xmorel
messages: + msg372358
2020-03-23 05:17:57laike9msetnosy: + laike9m
2020-01-20 18:07:15cheryl.sabellasetversions: + Python 3.8, Python 3.9, - Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
2019-01-30 14:54:29utkarsh2102setmessages: + msg334563
2018-11-23 08:58:28serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg330300
2018-11-22 22:41:40utkarsh2102setnosy: + utkarsh2102
2018-11-22 22:12:56utkarsh2102setkeywords: + patch
stage: patch review
pull_requests: + pull_request9921
2017-07-19 08:49:57marco.buttusetnosy: + marco.buttu
messages: + msg298644
2017-07-17 19:38:27jalexvigsetpull_requests: + pull_request2803
2017-07-17 19:01:45jalexvigsetpull_requests: + pull_request2802
2017-07-17 17:29:35jalexvigcreate