Skip to content

[Bug]: collections._tuplegetter accepts fewer than two arguments and keyword arguments #1249

Open

Description

@jseop-lim

Describe the bug

_collections._tuplegetter treats index and doc as optional keyword-capable parameters. A call with fewer than two arguments builds a getter for index 0, while CPython requires exactly two positional arguments and rejects keywords.

Operating system

macOS

CPU architecture

ARM64

GraalPy version

master a3009f9 (Python 3.13.14); also reproduced on 25.0.2 (Python 3.12.8)

JDK version

No response

Context configuration

No response

Steps to reproduce

import collections
print(type(collections._tuplegetter(0)))

GraalPy master a3009f9:

<class '_collections._tuplegetter'>

Expected behavior

CPython 3.13.14 (same on 3.12.13):

TypeError: _tuplegetter expected 2 arguments, got 1

Stack trace

Additional context

_tuplegetter() with no arguments also succeeds, and _tuplegetter(0, doc=None) and _tuplegetter(index=0, doc=None) succeed where CPython raises TypeError: _tuplegetter() takes no keyword arguments.

Root Cause

The tp_new of TupleGetterNode declares @SlotSignature(name = J_TUPLE_GETTER, parameterNames = {"cls", "index", "doc"}) with no minimum or positional-only count (TupleGetterBuiltins.java#L97-L99), so both arguments are optional and can be passed by keyword. CPython's tuplegetter_new rejects keywords and then calls _PyArg_CheckPositional("_tuplegetter", nargs, 2, 2) (_collectionsmodule.c.h#L607-L613).

Fix Suggestion

Add minNumOfPositionalArgs = 3, numOfPositionalOnlyArgs = 3 to that @SlotSignature.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions