GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — code.co_positions behaviour does not match documentation · Issue #100117 · python/cpython

code.co_positions behaviour does not match documentation #100117

New issue
Copy link
New issue
Copy link
Closed
#119364
Closed
code.co_positions behaviour does not match documentation#100117
#119364
Copy link
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly 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

@iritkatriel
iritkatriel
opened on Dec 8, 2022
Issue body actions

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

Activity

  1. iritkatriel
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    on Dec 8, 2022
  2. iritkatriel commented on Dec 8, 2022

    @iritkatriel
    iritkatriel
    on Dec 8, 2022
    MemberAuthor
    More actions

    CC @markshannon @brandtbucher .

  3. iritkatriel
    changed the title [-]error documentation of code.co_positions[/-] [+]error in documentation of code.co_positions[/+] on Dec 8, 2022
  4. iritkatriel
    changed the title [-]error in documentation of code.co_positions[/-] [+]code.co_positions behaviour does not match documentation[/+] on Dec 12, 2022
  5. brandtbucher commented on Dec 21, 2022

    @brandtbucher
    brandtbucher
    on Dec 21, 2022
    Member
    More actions

    I think this is probably just a place where the docs could be improved.

    Are you suggesting replacing "instruction" with "code unit"? Or adding a note that inline CACHE "instructions" are included? I'd be fine with either.

  6. iritkatriel commented on Dec 22, 2022

    @iritkatriel
    iritkatriel
    on Dec 22, 2022
    MemberAuthor
    More actions

    We discussed this at the meeting and I think the view was that the implementation needs to change. @markshannon ?

  7. markshannon commented on Dec 22, 2022

    @markshannon
    markshannon
    on Dec 22, 2022
    Member
    More actions

    I don't think we can change the current behavior of emitting one tuple per code unit . The docs should reflect that behaviour.

    I think it is co_lines() that we should modify. We can merge successive tuples with the same line number, now that #99556 is merged.

  8. markshannon
    added a commit that references this issue on Jan 10, 2023

    GH-100117: Make `co_lines` more efficient (GH-100447)

    f07daaf
  9. brandtbucher
    closed this as completedon Jan 13, 2023
  10. iritkatriel
    reopened this on Dec 11, 2023
  11. iritkatriel commented on Dec 11, 2023

    @iritkatriel
    iritkatriel
    on Dec 11, 2023
    MemberAuthor
    More actions

    This shouldn't have been closed, the doc is still incorrect.

  12. iritkatriel
    added
    3.13only security fixesonly security fixes
    on Dec 11, 2023
  13. iritkatriel
    added a commit that references this issue on May 21, 2024

    pythongh-100117: Fix inaccuracy in documentation of the CodeObject's …

    8abc8a8
  14. iritkatriel
    closed this as completedin #119364on May 31, 2024
  15. iritkatriel
    added a commit that references this issue on May 31, 2024

    gh-100117: Fix inaccuracy in documentation of the CodeObject's co_pos…

    015b1fd
  16. miss-islington
    added 3 commits that reference this issue on May 31, 2024

    pythongh-100117: Fix inaccuracy in documentation of the CodeObject's …

    6e7e27b

    pythongh-100117: Fix inaccuracy in documentation of the CodeObject's …

    f421bbe

    pythongh-100117: Fix inaccuracy in documentation of the CodeObject's …

    75c103e
  17. iritkatriel
    added 2 commits that reference this issue on May 31, 2024

    [3.12] gh-100117: Fix inaccuracy in documentation of the CodeObject's…

    045be77

    [3.13] gh-100117: Fix inaccuracy in documentation of the CodeObject's…

    24e3a8a
  18. estyxx
    added a commit that references this issue on Jul 17, 2024

    pythongh-100117: Fix inaccuracy in documentation of the CodeObject's …

    2c7ce95
  19. ambv
    added a commit that references this issue on Sep 4, 2024

    [3.11] gh-100117: Fix inaccuracy in documentation of the CodeObject's…

    851821d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixesonly security fixes3.12only security fixesonly security fixes3.13only security fixesonly 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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.