← 输入框|github.com|刷新
Skip to content

PyTuple_GetSlice docs minor inaccuracy #82738

Closed

Description

@wimglenn
mannequin
BPO 38557
Nosy @terryjreedy, @serhiy-storchaka, @wimglenn, @miss-islington
PRs
  • bpo-38557: Improve documentation for list and tuple C API. #16925
  • [3.8] bpo-38557: Improve documentation for list and tuple C API. (GH-16925) #16933
  • [3.7] bpo-38557: Improve documentation for list and tuple C API. (GH-16925) #16934
  • [2.7] bpo-38557: Improve documentation for list and tuple C API. (GH-16925) #16935
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2019-10-26.21:14:51.193>
    created_at = <Date 2019-10-22.15:51:00.228>
    labels = ['3.8', 'type-feature', '3.7', '3.9', 'docs']
    title = 'PyTuple_GetSlice docs minor inaccuracy'
    updated_at = <Date 2019-10-26.21:14:51.193>
    user = 'https://github.com/wimglenn'

    bugs.python.org fields:

    activity = <Date 2019-10-26.21:14:51.193>
    actor = 'serhiy.storchaka'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2019-10-26.21:14:51.193>
    closer = 'serhiy.storchaka'
    components = ['Documentation']
    creation = <Date 2019-10-22.15:51:00.228>
    creator = 'wim.glenn'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38557
    keywords = ['patch']
    message_count = 7.0
    messages = ['355141', '355385', '355388', '355426', '355428', '355429', '355430']
    nosy_count = 5.0
    nosy_names = ['terry.reedy', 'docs@python', 'serhiy.storchaka', 'wim.glenn', 'miss-islington']
    pr_nums = ['16925', '16933', '16934', '16935']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue38557'
    versions = ['Python 2.7', 'Python 3.7', 'Python 3.8', 'Python 3.9']

    Activity

    1. wimglenn commented on Oct 22, 2019

      wimglennmannequin
      MannequinAuthor

      https://docs.python.org/3/c-api/tuple.html#c.PyTuple_GetSlice

      In the c-api it says (emphasis mine):

          PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)¶
          Return value: New reference.
      Take a slice of the tuple pointed to by p from low to high and return it **as a new tuple**.
      

      But when slicing the entire tuple, CPython will return already existing instance, not a new tuple.

      https://github.com/python/cpython/blob/3.8/Objects/tupleobject.c#L448-L451

      I propose the language in the docs be loosened so as not to tie the hands of implementation

    2. added
      3.7 (EOL)
      3.8 (EOL)
      3.9 (EOL)
      on Oct 22, 2019
    3. added
      docs
      type-feature
      on Oct 22, 2019
    4. terryjreedy commented on Oct 25, 2019

      @terryjreedy
      Member
      Verified from Python.
      >>> t = (1,2,3)
      >>> t2 = t[:]
      >>> id(t), id(t2)
      (1672756229504, 1672756229504)
      A partial slice cannot the original tuple, so I presume that the emphasis is about returning a (new) *tuple*, rather than some sort of view of the original.  However,
              Py_INCREF(a);
              return (PyObject *)a;
      date back to at least 1997 (GvR), so the optimization is not new.  I don't know what should replace 'New reference.'  'Old or new reverence.'?

      "Take a slice of the tuple pointed to by p from low to high and return it **as a new tuple**."

      could be replaces with

      "Return the slice of the tuple point to by p for low to high. If it is a proper subslice, return a new tuple."

      This leave it undefined when a complete slice.

    5. serhiy-storchaka commented on Oct 25, 2019

      @serhiy-storchaka
      Member

      The part about "new tuple" can be removed. The documentation olready contains an automatically generated note about a new reference.

      PR 16925 improves the documentation for getting/setting items/slices of lists and tuples.

    6. serhiy-storchaka commented on Oct 26, 2019

      @serhiy-storchaka
      Member

      New changeset d898d20 by Serhiy Storchaka in branch 'master':
      bpo-38557: Improve documentation for list and tuple C API. (GH-16925)
      d898d20

    7. miss-islington commented on Oct 26, 2019

      @miss-islington
      Contributor

      New changeset 7356e10 by Miss Skeleton (bot) in branch '2.7':
      bpo-38557: Improve documentation for list and tuple C API. (GH-16925)
      7356e10

    8. miss-islington commented on Oct 26, 2019

      @miss-islington
      Contributor

      New changeset 334fc92 by Miss Skeleton (bot) in branch '3.7':
      bpo-38557: Improve documentation for list and tuple C API. (GH-16925)
      334fc92

    9. miss-islington commented on Oct 26, 2019

      @miss-islington
      Contributor

      New changeset 4992dc6 by Miss Skeleton (bot) in branch '3.8':
      bpo-38557: Improve documentation for list and tuple C API. (GH-16925)
      4992dc6

    10. transferred this issue fromon Apr 10, 2022
    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.7 (EOL)3.8 (EOL)3.9 (EOL)docstype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions