Skip to content

Fix inspect.signature() of operator.{attrgetter,itemgetter,methodcaller} instances #118285

Closed
@dgilland

Description

@dgilland

Bug report

Bug description:

On Python 3.12.3 and 3.11.9, it looks like the inspect.Signature object for operator's attrgetter, itemgetter, and methodcaller classes doesn't match their __call__ method signature:

>>> import inspect
>>> import operator
>>> inspect.signature(operator.attrgetter("spam"))
<Signature (*args, **kwargs)>
>>> inspect.signature(operator.itemgetter("spam"))
<Signature (*args, **kwargs)>
>>> inspect.signature(operator.methodcaller("spam"))
<Signature (*args, **kwargs)>

but their __call__ methods only accept a single argument:

# attrgetter / itemgetter
    def __call__(self, obj):
        return self._call(obj)

# methodcaller
    def __call__(self, obj):
        return getattr(obj, self._name)(*self._args, **self._kwargs)

CPython versions tested on:

3.11, 3.12

Operating systems tested on:

macOS

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions