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

Use getfullargspec if available #458

Closed
wants to merge 2 commits into from
Closed

Use getfullargspec if available #458

wants to merge 2 commits into from

Conversation

Bouke
Copy link

@Bouke Bouke commented Jul 10, 2017

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
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
Copy link
Contributor

haydenflinner commented Nov 6, 2018

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

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
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
Copy link

nyurik commented Sep 28, 2019

@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

Any movement on getting this small PR merged in?

@Crocmagnon
Copy link

Crocmagnon commented Dec 31, 2021

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

@neozenith
Copy link

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
Copy link

neozenith commented Mar 21, 2022

This also duplicates work in PR #606

@Crocmagnon
Copy link

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

@manykarim
Copy link

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

this fixes #891

@caphrim007
Copy link

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

@bitprophet
Copy link
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.