-
Notifications
You must be signed in to change notification settings - Fork 371
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
Issue with Python 3.11, or type annotations: the inspect module changed #833
Comments
I'm getting a similar error in Python 3.10 if I use type annotations. |
It seems like invoke is not python 3.11 ready at all |
Broken against the 3.11 release. Looks like @bitprophet has been working on getting rid of Python 2 support, which would make fixing this issue easier. That said, I agree with the original poster that a potential fix already exists in |
Until an update is released this can be worked around temporarily with a hack to monkey patch the import inspect
if not hasattr(inspect, 'getargspec'):
inspect.getargspec = inspect.getfullargspec
from invoke import task
@task
def say_hello(c):
print("Hello, World!") |
I ended up forking this repo, applying this commit to the fork, and then referencing the package as Others could do likewise with their own forks, if they need to be unblocked. Not a great long-term solution, obviously.... |
Invoke is broken on 3.11 pyinvoke/invoke#833
Invoke is broken on 3.11 pyinvoke/invoke#833
This monkeypatch worked for me - adapted from @zelo's in #606 # type: ignore
from collections import namedtuple
from inspect import getfullargspec
from unittest.mock import patch
import invoke
def fix_annotations():
"""
Pyinvoke doesn't accept annotations by default, this fix that
Based on: @zelo's fix in https://github.com/pyinvoke/invoke/pull/606
Context in: https://github.com/pyinvoke/invoke/issues/357
Python 3.11 https://github.com/pyinvoke/invoke/issues/833
"""
ArgSpec = namedtuple("ArgSpec", ["args", "defaults"])
def patched_inspect_getargspec(func):
spec = getfullargspec(func)
return ArgSpec(spec.args, spec.defaults)
org_task_argspec = invoke.tasks.Task.argspec
def patched_task_argspec(*args, **kwargs):
with patch(
target="inspect.getargspec", new=patched_inspect_getargspec, create=True
):
return org_task_argspec(*args, **kwargs)
invoke.tasks.Task.argspec = patched_task_argspec |
Invoke doesn't work with Python 3.11 so far. pyinvoke/invoke#833 (comment) pyinvoke/invoke#458 pyinvoke/invoke#606
This reverts commit 93ab8e8. The OpenStack SDK is not yet happy with Python 3.11: AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'? More details: pyinvoke/invoke#833 Closes osism/issues#392
This reverts commit 93ab8e8. The OpenStack SDK is not yet happy with Python 3.11: AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'? More details: pyinvoke/invoke#833 Closes osism/issues#392 Signed-off-by: Christian Berendt <[email protected]>
This reverts commit 93ab8e8. The OpenStack SDK is not yet happy with Python 3.11: AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'? More details: pyinvoke/invoke#833 Closes osism/issues#392 Signed-off-by: Christian Berendt <[email protected]>
I think this is fixed by 406a45e, we just need a release |
My take on the workaround, with a warning once it becomes unneccessary: # Work around https://github.com/pyinvoke/invoke/issues/833
try:
@task
def ignore_me(c):
"""Only defined to detect an invoke issue, ignore me"""
pass
except AttributeError as e:
if e.args != ("module 'inspect' has no attribute 'getargspec'",):
raise
import invoke.tasks # type: ignore
invoke.tasks.inspect.getargspec = invoke.tasks.inspect.getfullargspec # type: ignore
else:
import warnings
warnings.warn(
"Please remove unneccessary monkeypatch, invoke works with python311 now"
) |
it works for me on official Nexus 20, thanks it would be great if it could be put in the next update |
it will be in the next release, whenever there is one :) |
Yup, 2.0.0 is out, so if anyone is still getting this error please let us know! |
I just tried with invoke=2.0.0 and still getting the same error, here is the traceback:
|
@barismutanpicus seems to be related to flask_class not invoke as you can see in the traceback |
Yup, that's not us this time 😇 |
There's no mention of BTW, I now feel guilty that this issue's name is attracting a lot of false positives :P |
I'm having an issue running invoke (latest) in Python 3.11-dev (3.11.0a3). For this tasks file, this is the trace I get:
It works perfectly fine for any other Python version I tried (3.7, 3.8, 3.9, 3.10, PyPy3.7, PyPy3.8, Stackless3.7, Stackless3.8).
The module
inspect
does indeed not have said attribute, and I see that there's a potential replacement done ininvoke.vendor.decorator
for some reason.The text was updated successfully, but these errors were encountered: