Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PyTuple_GetSlice docs minor inaccuracy #82738

Closed
wimglenn mannequin opened this issue Oct 22, 2019 · 7 comments
Closed

PyTuple_GetSlice docs minor inaccuracy #82738

wimglenn mannequin opened this issue Oct 22, 2019 · 7 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement

Comments

@wimglenn
Copy link
Mannequin

wimglenn mannequin commented Oct 22, 2019

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']

    @wimglenn
    Copy link
    Mannequin Author

    wimglenn mannequin commented Oct 22, 2019

    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 highReturn 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

    @wimglenn wimglenn mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes labels Oct 22, 2019
    @wimglenn wimglenn mannequin assigned docspython Oct 22, 2019
    @wimglenn wimglenn mannequin added docs Documentation in the Doc dir type-feature A feature request or enhancement labels Oct 22, 2019
    @terryjreedy
    Copy link
    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.

    @serhiy-storchaka
    Copy link
    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.

    @serhiy-storchaka
    Copy link
    Member

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

    @miss-islington
    Copy link
    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

    @miss-islington
    Copy link
    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

    @miss-islington
    Copy link
    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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes docs Documentation in the Doc dir type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants