question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

operator.attrgetter/itemgetter is not supported by signature

See original GitHub issue

Hi there 👋 I’m back with another issue 😄 Here’s a reproducible example:

from operator import attrgetter
from plum import Function
f = Function(lambda x: x)
pf = Function(f)
g = attrgetter('a')  # same holds for operator.itemgetter
g = pf.dispatch(g)
g(0)
ValueError: callable operator.attrgetter('a') is not supported by signature

It might be possible for us to implement a workaround on our side but it would be great if it were handled by plum. My thinking, which isn’t very elegant, is to wrap it in another callable that passes through and to set that callable’s __signature__, which inspect.signature uses as a sort of cache. I haven’t tested that yet.

cc @wesselb


For completeness, the following also fails with a different error, but isn’t a use-case for us atm so less crucial:

from operator import attrgetter
from plum import dispatch
f = attrgetter('a')
pf = dispatch(f)
AttributeError: 'operator.attrgetter' object has no attribute '__qualname__'

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
seeMcommented, Jun 6, 2022

Many thanks, it’s working well!

1reaction
wesselbcommented, Jun 6, 2022

This should now work in v1.5.16!

Read more comments on GitHub >

github_iconTop Results From Across the Web

operator.{itemgetter,attrgetter,methodcaller} don't have ...
operator functions are often used when programming in a functional style, and sometimes signature inspection is useful to e.g. determine whether ...
Read more >
Python - NameError: name itemgetter not defined
2. Try from operator import itemgetter or sorted(b,key=operator.itemgetter(1)) . – niemmi. Apr 18, 2016 at 5:01 ; 4. Either you do operator.itemgetter or...
Read more >
Optional kwarg making attrgetter & itemgetter always return a ...
attrgetter and itemgetter are both very useful functions, but both have a significant pitfall if the arguments passed in are validated but not...
Read more >
Issue 4124: Patch for adding "default" to itemgetter and attrgetter
This is a patch for adding "default" keyword to itemgetter and attrgetter. This way you can do: >>> f = itemgetter(0, default=1) >>>...
Read more >
Sorting in python using operator.itemgetter and operator ...
attrgetter. 1. Understanding operator.itemgetter(attribute) or operator.itemgetter(*attribute). Returns a callable object that fetches item from ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found