Skip to content

Use getfullargspec if available - #458

Closed
Bouke wants to merge 2 commits into
pyinvoke:mainfrom
Bouke:patch-1
Closed

Bouke wants to merge 2 commits into
pyinvoke:mainfrom
Bouke:patch-1

Conversation

@Bouke

@Bouke Bouke commented Jul 10, 2017

Copy link
Copy Markdown

I like using annotations in Python as it allows my IDE to provide completions:

@task
def test(c: Connection):
    c. # < IDE can now offer completions based on the Connection type

inspect.getargspec is deprecated since Python 3. It is still available on 3.6, however it throws an error when one uses function annotations:

ValueError: Function has keyword-only parameters or annotations, use getfullargspec() API which can support them

The new api inspect.getfullargspecs is a drop-in replacement according to the stdlib authors:

Deprecated since version 3.0: Use getfullargspec() for an updated API that is usually a drop-in replacement, but also correctly handles function annotations and keyword-only parameters.

This PR tries to use getfullargspecs and if that's not available, falls back to getargspecs.

@bitprophet

Copy link
Copy Markdown
Member

Thanks! This should be linked to #248 / #373 / #372 and I suspect the PRs in that list may obviate this one (or vice versa). No time to compare at the moment but if someone else does, please comment!

@haydenflinner

haydenflinner commented Nov 6, 2018 •

Copy link
Copy Markdown
Contributor

FWIW the vendored decorator includes this fallback as well, IIRC it does something a little more involved but it's been a while since I last looked

@neighthan

Copy link
Copy Markdown

It would be nice if we could merge in one of the PRs to make invoke work properly on Python 3. As this one is extremely short (code review should take just a minute) and does exactly what the error message says should be done to avoid this error, it seems a good candidate. There are other PRs (well, at least one) that address the same issue, but I think just getting something merged now would be a great benefit. It's been two and a half years since #357 was created, and I'd be glad to stop fixing it myself with each install of invoke.

@haydenflinner

Copy link
Copy Markdown
Contributor

@neighthan rather than patching your installs of invoke, just pip install magicinvoke, it does the same thing but includes a few more bugfixes.

@nyurik

nyurik commented Sep 28, 2019 •

Copy link
Copy Markdown

@bitprophet hi, thanks for all the hard work on this project! This PR seems like a simple solution to using typing in Python3 -- are there any blockers for merging it? Thanks!!!

As a temporary workaround, adding quotes around the type seems to work in Python 3.7+, and an explicit variable declaration might work everywhere.

from invoke import task, Context

@task
def mytask(c: 'Context'):  # python3.7+
    ...

@task
def mytask(c):
    c: Context  # python3.5+ (?)
    ...

@MichaelRBond

Copy link
Copy Markdown

Any movement on getting this small PR merged in?

@Crocmagnon

Crocmagnon commented Dec 31, 2021 •

Copy link
Copy Markdown

I'd love to see this merged (and released) too 🙏🏻

@neozenith

Copy link
Copy Markdown

Hi 👋
I'm starting to volunteer on triage on PRs and issues.

The messaging for the roadmap can be found here:
https://bitprophet.org/projects/#roadmap

Key items that are putting back pressure are:

  • Migrating CI [DONE]
  • Dropping Python2 support

The latter task is the more important task which will make future type annotation support easier.

Given this PR has a high number of 👍 votes on it I'll take that as community feedback it has good ROI for me to investigate. We do appreciate everyone's patience as we have limited volunteering time and cognitive bandwidth.

@neozenith

neozenith commented Mar 21, 2022 •

Copy link
Copy Markdown

This also duplicates work in PR #606

@Crocmagnon

Copy link
Copy Markdown

I'd argue on the contrary that #606 duplicated this work, given the timeframe 🙂

@manykarim

Copy link
Copy Markdown

With the recent Python 3.11 Release. the getargspec() has been removed.
https://docs.python.org/3.11/whatsnew/3.11.html

So as of now, invoke does not work in Python 3.11 when using the Tasks decorator.
Would be great if this PR could be merged, as it seems to be a minimal change.

Is there anything I could do to support?

@Mateusz-Grzelinski

Copy link
Copy Markdown

this fixes #891

@caphrim007

Copy link
Copy Markdown

@bitprophet i can also verify this patch addresses python 3.11. would be super cool if it could be merged.

@bitprophet

Copy link
Copy Markdown
Member

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

@bitprophet bitprophet closed this Jan 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.