Repository navigation
Issue with Python 3.11, or type annotations: the inspect module changed #833
Copy link
Copy link
Closed
Description
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:
root@18bb2bd21aaa:/b2s# poetry run inv tests
Traceback (most recent call last):
File "/root/.cache/pypoetry/virtualenvs/blake2signer-uv6dtlQx-py3.11/bin/inv", line 8, in <module>
sys.exit(program.run())
^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/blake2signer-uv6dtlQx-py3.11/lib/python3.11/site-packages/invoke/program.py", line 373, in run
self.parse_collection()
^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/blake2signer-uv6dtlQx-py3.11/lib/python3.11/site-packages/invoke/program.py", line 465, in parse_collection
self.load_collection()
^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/blake2signer-uv6dtlQx-py3.11/lib/python3.11/site-packages/invoke/program.py", line 696, in load_collection
module, parent = loader.load(coll_name)
^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/blake2signer-uv6dtlQx-py3.11/lib/python3.11/site-packages/invoke/loader.py", line 76, in load
module = imp.load_module(name, fd, path, desc)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/imp.py", line 235, in load_module
return load_source(name, filename, file)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/imp.py", line 172, in load_source
module = _load(spec)
^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 721, in _load
File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 902, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "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/b2s/tasks.py", line 11, in <module>
def flake8(ctx):
^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/blake2signer-uv6dtlQx-py3.11/lib/python3.11/site-packages/invoke/tasks.py", line 325, in task
return klass(args[0], **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/blake2signer-uv6dtlQx-py3.11/lib/python3.11/site-packages/invoke/tasks.py", line 76, in __init__
self.positional = self.fill_implicit_positionals(positional)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/blake2signer-uv6dtlQx-py3.11/lib/python3.11/site-packages/invoke/tasks.py", line 167, in fill_implicit_positionals
args, spec_dict = self.argspec(self.body)
^^^^^^^^^^^^^^^^^^^^^^^
File "/root/.cache/pypoetry/virtualenvs/blake2signer-uv6dtlQx-py3.11/lib/python3.11/site-packages/invoke/tasks.py", line 153, in argspec
spec = inspect.getargspec(func)
^^^^^^^^^^^^^^^^^^
AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'?
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 in invoke.vendor.decorator for some reason.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
ktbarrett commentedon Sep 4, 2022
I'm getting a similar error in Python 3.10 if I use type annotations.
inspect.getargspecwas deprecated in 3.0. After looking at the Python 2 documentation, it seems it doesn't have the suggested replacementinspect.getfullargspecnor the more flexibleinspect.signature. Fixing this is going to involve some version specific code.kasium commentedon Sep 9, 2022
It seems like invoke is not python 3.11 ready at all
emcd commentedon Oct 26, 2022
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
invoke.vendor.decorator. Seems like theinvoke.taskscode could use the replacementgetargspecimplementation provided in that module and we would have a workaround for the issue.ian-em commentedon Oct 27, 2022
Until an update is released this can be worked around temporarily with a hack to monkey patch the
inspectmodule in yourtasks.pyfile. Here is an example working for me on Python 3.11:manykarim commentedon Oct 27, 2022
Both PRs below would solve it, right?
#458
#606
emcd commentedon Oct 29, 2022
I ended up forking this repo, applying this commit to the fork, and then referencing the package as
invoke @ git+https://github.com/emcd/invoke.git@fb40a3c79b3fa59cb589a642d0c4b8fa87ca082e, whichpip(and presumably other Python package utilities/systems) can use to build/install the package directly from the repo. Doing this fixed/worked around the Python 3.11 compatibility issue for me.Others could do likewise with their own forks, if they need to be unblocked. Not a great long-term solution, obviously....
Use Python 3.10
Use Python 3.10
janrito commentedon Nov 12, 2022
This monkeypatch worked for me - adapted from @zelo's in #606
Package with Python 3.10
Invoke is not compatible with Python 3.11
Revert "Use 3.11-slim as base image (#259)"
Revert "Use 3.11-slim as base image (#259)"
Revert "Use 3.11-slim as base image (#259)" (#304)
11 remaining items
kasium commentedon Feb 15, 2023
@barismutanpicus seems to be related to flask_class not invoke as you can see in the traceback
bitprophet commentedon Feb 16, 2023
Yup, that's not us this time 😇
HacKanCuBa commentedon Mar 8, 2023
There's no mention of
invokein that trace, it doesn't seem to be related to this package :)Try on
gnome-language-selectorbug tracker, or ubuntu's bug tracker.BTW, I now feel guilty that this issue's name is attracting a lot of false positives :P
I'm gonna change the title
[-]AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'?[/-][+]Issue with Python 3.11, or type annotations: the inspect module changed[/+]Build package by Python 3.11
Build package by Python 3.11
Build package by Python 3.11
Build package by Python 3.11
Build package by Python 3.11
Patching inspect for compat with Python 3.11
Patching inspect for compat with Python 3.11
chore(tasks): remove an old workaround
chore(tasks): remove an old workaround
chore(tasks): remove an old workaround
Add uv, use `uv sync --extra vllm`