[issue45492] stdlib inspect documentation on code.co_names is incorrect
New submission from Dutcho <dutcho@ziggo.nl>: 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
---------- assignee: docs@python components: Documentation messages: 404068 nosy: Dutcho, docs@python priority: normal severity: normal status: open title: stdlib inspect documentation on code.co_names is incorrect versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45492> _______________________________________
Change by Irit Katriel <iritkatriel@gmail.com>: ---------- keywords: +easy versions: -Python 3.6, Python 3.7, Python 3.8 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45492> _______________________________________
Change by Stanley <ostanley.lee@gmail.com>: ---------- keywords: +patch nosy: +slateny nosy_count: 2.0 -> 3.0 pull_requests: +29585 stage: -> patch review pull_request: https://github.com/python/cpython/pull/31456 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45492> _______________________________________
Irit Katriel <iritkatriel@gmail.com> added the comment: 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/3257d49d236e5f3453fe9d2fd8338bcdfe9... ---------- nosy: +iritkatriel _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45492> _______________________________________
Change by Irit Katriel <iritkatriel@gmail.com>: ---------- pull_requests: +29765 pull_request: https://github.com/python/cpython/pull/31645 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45492> _______________________________________
Irit Katriel <iritkatriel@gmail.com> added the comment: 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/eb65e46b9b28103767c115ccf71a97a9f42... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45492> _______________________________________
Change by Irit Katriel <iritkatriel@gmail.com>: ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed versions: -Python 3.9 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue45492> _______________________________________
participants (3)
-
Dutcho -
Irit Katriel -
Stanley