You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>>fromnumpy.core.overridesimportverify_matching_signatures>>>defa(*, foo=1): pass>>>defb(*, bar=2): pass>>>verify_matching_signatures(a, b)
# does not fail
A correct implementation could look like:
defverify_matching_signatures(implementation, dispatcher):
importinspectimplementation_sig=inspect.signature(implementation)
dispatcher_sig=inspect.signature(dispatcher)
# replace defaults with None and remove annotationsimplementation_with_none_sig=implementation_sig.replace(
parameters=[
p.replace(
annotation=inspect.Parameter.empty,
default=inspect.Parameter.emptyifp.defaultisinspect.Parameter.emptyelseNone
)
forpinimplementation_sig.parameters.values()
],
return_annotation=inspect.Signature.empty
)
ifdispatcher_sig!=implementation_with_none_sig:
raiseRuntimeError(
'dispatcher for {} has the wrong function signature:\n'' expected: {}\n'' got: {}'
.format(
implementation, implementation_with_none_sig, dispatcher_sig
)
)
which gives:
>>> verify_matching_signatures(a, b)
RuntimeError: dispatcher for <function a at 0x0000020080E14B80> has the wrong function signature:
expected: (*, foo=None)
got: (*, bar=2)
Unfortunately, this implementation seems to slow down the import time by 5%.
The text was updated successfully, but these errors were encountered:
Numpy inspection doesn't handle kwonly arguments. It can either cause the arguments not to output from the inspection, or even mess up to order of * and ** arguments, since the kwonly args aren't counted (messing up the index of the names). Example:
I am fixing the issue in inspection, having it count the code.co_kwonlyargcount and read function.__kwdefaults__, along with adding your test-case for numpy.core.overrides.verify_matching_signatures. It seems more appropriate than bypassing the bug in the inspection functions, but it's possible that it has side effects if something is expecting this (wrong) behaviour somewhere else.
Uh oh!
There was an error while loading. Please reload this page.
Reproducing code example:
A correct implementation could look like:
which gives:
Unfortunately, this implementation seems to slow down the import time by 5%.
The text was updated successfully, but these errors were encountered: