Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Current implementation of decorators loses function signature #2446

Closed
sphuber opened this issue Feb 2, 2019 · 0 comments · Fixed by #2991
Closed

Current implementation of decorators loses function signature #2446

sphuber opened this issue Feb 2, 2019 · 0 comments · Fixed by #2991

Comments

@sphuber
Copy link
Contributor

sphuber commented Feb 2, 2019

The current implementation of decorators in aiida-core cause the functions that are wrapped to lose their function signature. This will cause inspect to fail miserably. The same problem occurs with it losing its __name__ and __doc__, which is sometimes fixed by using functools.wraps, however, that does not properly restore the function signature. Example:

import inspect
from aiida.cmdline.utils import decorators

def unwrapped(a, b):
    pass

inspect.getargspec(wrapped)
ArgSpec(args=['a', 'b'], varargs=None, keywords=None, defaults=None)

Now when we wrap it, for example with with_dbenv decorator, we get:

@decorators.with_dbenv()
def wrapped(a, b):
    pass

inspect.getargspec(wrapped)
ArgSpec(args=[], varargs='args', keywords='kwargs', defaults=None)

Now this is currently not causing any problems, that we know of, but it might in the future. In addition, I use the inspect functionality in launch scripts that I have to wrap with with_dbenv and those now stopped working. There are various solutions, of which the wrapt library is the best as in most correct, but also slowest. Let's discuss if we would be willing to put this in our dependencies and fix our decorators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant