-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
The documentation of co_positions() says:
The iterator returns tuples containing the (start_line, end_line, start_column, end_column). The i-th tuple corresponds to the position of the source code that compiled to the i-th instruction.
I think this is incorrect, because the iterator returns tuples for cache entries as well:
>>> def f():
... a.b = 1
...
>>> import dis
>>> dis.dis(f)
1 0 RESUME 0
2 2 LOAD_CONST 1 (1)
4 LOAD_GLOBAL 0 (a)
16 STORE_ATTR 1 (b)
26 LOAD_CONST 0 (None)
28 RETURN_VALUE
>>> len(list(f.__code__.co_positions()))
15
>>> from pprint import pprint as pp
>>> pp(list(f.__code__.co_positions()))
[(1, 1, 0, 0),
(2, 2, 8, 9),
(2, 2, 2, 3),
(2, 2, 2, 3),
(2, 2, 2, 3),
(2, 2, 2, 3),
(2, 2, 2, 3),
(2, 2, 2, 3),
(2, 2, 2, 5),
(2, 2, 2, 5),
(2, 2, 2, 5),
(2, 2, 2, 5),
(2, 2, 2, 5),
(2, 2, 2, 5),
(2, 2, 2, 5)]
>>>
Linked PRs
- GH-100117: Make
co_lines
more efficient #100447 - gh-100117: Fix inaccuracy in documentation of the CodeObject's co_positions field. #119364
- [3.13] gh-100117: Fix inaccuracy in documentation of the CodeObject's co_positions field. (GH-119364) #119869
- [3.12] gh-100117: Fix inaccuracy in documentation of the CodeObject's co_positions field. (GH-119364) #119870
- [3.11] gh-100117: Fix inaccuracy in documentation of the CodeObject's co_positions field. (GH-119364) #119871
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13bugs and security fixesbugs and security fixesdocsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error