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

Can't use python3 typing for tasks #777

Closed
sprat opened this issue Jan 4, 2021 · 3 comments
Closed

Can't use python3 typing for tasks #777

sprat opened this issue Jan 4, 2021 · 3 comments
Assignees

Comments

@sprat
Copy link

sprat commented Jan 4, 2021

I would like to use python3 typing on my tasks, e.g.:

@task
def hostname(c, hostname: str):
    """Define the hostname"""
    print(f'Setting hostname: {hostname}')
    c.sudo(f'hostnamectl set-hostname {hostname}')

However, it fails with the following error:

Traceback (most recent call last):
  File "/home/sylvain/.virtualenvs/fabric-nas/bin/fab", line 8, in <module>
    sys.exit(program.run())
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/invoke/program.py", line 373, in run
    self.parse_collection()
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/invoke/program.py", line 465, in parse_collection
    self.load_collection()
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/fabric/main.py", line 87, in load_collection
    super(Fab, self).load_collection()
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/invoke/program.py", line 696, in load_collection
    module, parent = loader.load(coll_name)
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/invoke/loader.py", line 76, in load
    module = imp.load_module(name, fd, path, desc)
  File "/usr/lib/python3.8/imp.py", line 234, in load_module
    return load_source(name, filename, file)
  File "/usr/lib/python3.8/imp.py", line 171, in load_source
    module = _load(spec)
  File "<frozen importlib._bootstrap>", line 702, in _load
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/sylvain/Dev/fabric-nas/fabfile.py", line 2, in <module>
    from lib import system
  File "/home/sylvain/Dev/fabric-nas/lib/system.py", line 5, in <module>
    def hostname(c, hostname: str):
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/fabric/tasks.py", line 71, in task
    return invoke.task(*args, **kwargs)
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/invoke/tasks.py", line 325, in task
    return klass(args[0], **kwargs)
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/fabric/tasks.py", line 21, in __init__
    super(Task, self).__init__(*args, **kwargs)
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/invoke/tasks.py", line 76, in __init__
    self.positional = self.fill_implicit_positionals(positional)
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/invoke/tasks.py", line 167, in fill_implicit_positionals
    args, spec_dict = self.argspec(self.body)
  File "/home/sylvain/.virtualenvs/fabric-nas/lib/python3.8/site-packages/invoke/tasks.py", line 153, in argspec
    spec = inspect.getargspec(func)
  File "/usr/lib/python3.8/inspect.py", line 1083, in getargspec
    raise ValueError("Function has keyword-only parameters or annotations"
ValueError: Function has keyword-only parameters or annotations, use inspect.signature() API which can support them

Can typing be supported in invoke?

@wawamanhunt
Copy link

there seem to be a few PRs to fix this problem but unsure when any will be merged, one of these PRs #458 has a few workarounds to this in the comments

@sprat
Copy link
Author

sprat commented Jan 16, 2021

Thanks for the information, I guess it won't be fixed anytime soon.

@neozenith neozenith self-assigned this Mar 26, 2022
@bitprophet
Copy link
Member

2.0.0 will be out soon & is now using inspect.signature!

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

No branches or pull requests

4 participants