Code Monkey home page Code Monkey logo

Comments (4)

Birne94 avatar Birne94 commented on May 24, 2024 1

These are the two error messages I receive when decorating a handler with an invalid signature (after removing the checks) on python 3.6.

TypeError: handler() takes 0 positional arguments but 1 was given
TypeError: handler() missing 1 required positional argument: 'bar'

on python 2.7 the error messages are

TypeError: handler() takes no arguments (1 given)
TypeError: handler() takes exactly 2 arguments (1 given)

In my opinion these error messages should be enough to figure out that the function definition is wrong. I also think most people are going to start by copying/modifying one of the examples, which should make clear that the function takes exactly one parameter.


For going around this issue, as you might have already observed, we use type hinting using the Python 2.7 syntax. What do you think about this approach?

I know about this syntax, but honestly I quite dislike a bit. I currently work around the issue by using a custom decorator which (actually by accident) removes the type annotations and gets the request_handler decorator to work.


Another workaround would be to differentiate between python 2.7 and 3.6 and use getargspec and getfullargspec or signature depending on the version. This would go in line with the deprecation of getargspec since python 3.0, so we cannot be sure that this function will be available forever.

The getfullargspec variant could look something along the lines of

            handle_arg_spec = inspect.getfullargspec(handle_func)
            if (len(handle_arg_spec.args) != 1 or
                    handle_arg_spec.varargs is not None or
                    handle_arg_spec.kwonlyargs != []):
                raise SkillBuilderException(
                    "Request Handler handle_func should only accept a single "
                    "input arg, handler input")

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 24, 2024 1

@Birne94 , thanks for the clear feedback. I am aware of the deprecation and had a task to update the api according to the Python version.

But I guess the error messages are clear enough for first time developers to figure out the issue.


on python 3.6.

TypeError: handler() takes 0 positional arguments but 1 was given
TypeError: handler() missing 1 required positional argument: 'bar'

on python 2.7 the error messages are

TypeError: handler() takes no arguments (1 given)
TypeError: handler() takes exactly 2 arguments (1 given)

I also think it would be good to mention in documentation on the interface details in general. As for type annotations, I support your argument that the syntax for Python 2.7 type annotations is a bit too much to add, for each function, and like Python 3's type annotations syntax. However, since we support Python 2.7 and Python 3.6> , we had to use a generic way.

Anyways, I think we can remove these checks in place for all the decorators on skill builders (eg: 1, 2, 3, 4). The necessary changes in the new PR is on the way!!

from alexa-skills-kit-sdk-for-python.

nikhilym avatar nikhilym commented on May 24, 2024

@Birne94, without the inspect.getargspeccheck, rather than the generic takes 1 positional argument but 2 were given error, we get missing .. required positional argument. This is because of the way the decorator builds up the AbstractRequestHandler class.

We had the signature check for providing a better exception message for skill developers. But we do understand type annotations is a sought after feature for Py3 developers.

For going around this issue, as you might have already observed, we use type hinting using the Python 2.7 syntax. What do you think about this approach?

from alexa-skills-kit-sdk-for-python.

Birne94 avatar Birne94 commented on May 24, 2024

@nikhilym Thank you for the quick response and actions!

from alexa-skills-kit-sdk-for-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.