-
Notifications
You must be signed in to change notification settings - Fork 204
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
Change decorator returned by request_handler to return the handler function #110
Conversation
…nction This allows to call the original function (e.g. to put it under test). Otherwise the original function name gets bound to NoneType and is not accesible anymore. (see https://stackoverflow.com/q/57349825/2980895)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is good. However, since we provide decorators across request handler, exception handler, request interceptor and response interceptor, it would be better to make the same changes across all these functions.
You are absolutely right, i did not think about the other decorators before. |
…bal_request_interceptor() and global_response_interceptor()
@nikhilym I added the return statements to the other decorators aswell and extended the tests to make sure the returned function is correct. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows to call the original function (e.g. to put it under test).
Otherwise the original function name gets bound to NoneType and is not
accesible anymore. (see https://stackoverflow.com/q/57349825/2980895)
Description
This pull request only adds a
return handle_func
to the wrapper function returned bySkillBuilder.request_handler()
. The wrapper returned by this function is a decorator and therefore should return a function by convention.Motivation and Context
The mentioned wrapper function does currently not return anything. Because of the logic of a decorator, the returned value of a decorator is bound to the original function name (see https://gist.github.com/Zearin/2f40b7b9cfc51132851a). Since the decorator does not return any value the original name is bound to
NoneType
.As a result the function is not accessible anymore after decoration. This is not a big deal in general, as you should not need to call the function manually in most cases, but there are two reasons to change that:
Currently it is not possible to unit test the handler functions, which results in lower code quality and also a more difficult development cycle.
Testing
The primary goal was to make the decorated handler functions testable. The success of the following test case verified the change in the first place:
from skill import some_handler
from tests import new_request
To make sure, that this change does not break anything else, I ran the local unittests of the SDK, which finished successfully.
Types of changes
Checklist
License