Content-Length: 294882 | pFad | https://github.com/python/cpython/issues/118285

ad Fix inspect.signature() of operator.{attrgetter,itemgetter,methodcaller} instances · Issue #118285 · python/cpython · GitHub
Skip to content

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

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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions









    ApplySandwichStrip

    pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


    --- a PPN by Garber Painting Akron. With Image Size Reduction included!

    Fetched URL: https://github.com/python/cpython/issues/118285

    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy