operator.attrgetter/itemgetter is not supported by signature
See original GitHub issueHi 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:
- Created a year ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Many thanks, it’s working well!
This should now work in
v1.5.16
!