Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Error using type hinting in Python 3.5 with manager.command annotation #169

Open

Description

@martyla

I'm trying to use type hinting from PEP 484 valid since Python 3.5, but I'm getting an error: ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them

Here's a sample:

from flask import Flask
from flask_script import Manager


app = Flask(__name__)
manager = Manager(app)


@manager.command
def test() -> None:
    print('Testing')

if __name__ == "__main__":
    manager.run()

It works fine if I define test() without the -> None annotation

Full stacktrace:

(env)$ python manage.py test
Traceback (most recent call last):
  File "manage.py", line 9, in <module>
    def test() -> None:
  File "/home/martin/tmp/flask-script-error/env/lib/python3.5/site-packages/flask_script/__init__.py", line 285, in command
    command = Command(func)
  File "/home/martin/tmp/flask-script-error/env/lib/python3.5/site-packages/flask_script/commands.py", line 118, in __init__
    args, varargs, keywords, defaults = inspect.getargspec(func)
  File "/usr/lib/python3.5/inspect.py", line 1045, in getargspec
    raise ValueError("Function has keyword-only arguments or annotations"
ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them

Any ideas?

Activity

  1. aquilax commented on Oct 14, 2016

    @aquilax

    Seems to be caused by inspect.getargspec, which is deprecated since python 3.0

    >>> def test() -> None:
    ...     print("test")
    
    >>> from inspect import getargspec
    
    >>> getargspec(test)
    ptpython3:1: DeprecationWarning: inspect.getargspec() is deprecated, use inspect.signature() instead
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/lib/python3.5/inspect.py", line 1045, in getargspec
        raise ValueError("Function has keyword-only arguments or annotations"
    ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
    Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
  2. sybrenstuvel commented on May 29, 2019

    @sybrenstuvel

    Changing the offending line to this solves the problem:

    args, varargs, keywords, defaults, _, _, _ = inspect.getfullargspec(func)
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions