Skip to content

Deprecating support for nested non-tuple sequences in PyArg_ParseTuple() #52

@serhiy-storchaka

Description

@serhiy-storchaka

See the old issue python/cpython#50333.

PyArg_ParseTuple() supports parsing nested sequences. For example, resource.setrlimit used PyArg_ParseTuple(args, "i(OO):setrlimit", &resource, &curobj, &maxobj) to parse its arguments. The problem is that it supports arbitrary sequences, including mutable sequences. Some format units store borrowed buffer or reference (e.g. "s" and "O"). If the sequence was mutated, the borrowed buffer or reference can be no longer valid. This is an innate flaw of such C API, it cannot be fixed in PyArg_ParseTuple(). The only solution is to deprecate accepting non-tuple sequences.

We can make the deprecation more lenient -- only reject non-tuple sequence if format units store borrowed buffer or reference. If all format units are like "i" or "s*", it is safe to accept a mutable sequence.

python/cpython#128374 implements this plan.

This may not require permission from the C API working group, but I'm asking just in case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions