GrahamDumpleton / wrapt

A Python module for decorators, wrappers and monkey patching.
BSD 2-Clause "Simplified" License
2.03k stars 231 forks source link

Python 3.11 ImportError: cannot import name 'formatargspec' from 'inspect' (pylint) #239

Open lilymooncake opened 1 year ago

lilymooncake commented 1 year ago
Traceback (most recent call last):
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
             ^^^^^^^^^^^^
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/pylint/__init__.py", line 21, in run_pylint
    from pylint.lint import Run as PylintRun
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/pylint/lint/__init__.py", line 75, in <module>
    from pylint.lint.parallel import check_parallel
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/pylint/lint/parallel.py", line 7, in <module>
    from pylint import reporters
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/pylint/reporters/__init__.py", line 25, in <module>
    from pylint import utils
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/pylint/utils/__init__.py", line 45, in <module>
    from pylint.utils.ast_walker import ASTWalker
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/pylint/utils/ast_walker.py", line 6, in <module>
    from astroid import nodes
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/astroid/__init__.py", line 48, in <module>
    import wrapt
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/wrapt/__init__.py", line 10, in <module>
    from .decorators import (adapter_factory, AdapterFactory, decorator,
  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/wrapt/decorators.py", line 34, in <module>
    from inspect import ismethod, isclass, formatargspec
ImportError: cannot import name 'formatargspec' from 'inspect' (/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/inspect.py)
lilymooncake commented 1 year ago

my workaround: go to => site-packages/wrapt/decorators.py and change all "formatargspec" to "formatargvalues"

GrahamDumpleton commented 1 year ago

You look to be using an old wrapt version. Are you pinning the version? You need to be using at least wrapt 1.14.0 if using Python 3.11.

lilymooncake commented 1 year ago

@GrahamDumpleton I updated the version information that I've used (which is 1.15.0)

GrahamDumpleton commented 1 year ago

And are you suggesting that it still fails with 1.15.0, or does it now work?

lilymooncake commented 1 year ago

Hi Graham, I went to site-packages/wrapt/decorators.py and change all "formatargspec" to "formatargvalues"

GrahamDumpleton commented 1 year ago

That isn't what I am asking. I am asking for clarification that if you ensure you are using version 1.15.0 that still had the issue.

The traceback you give above is not for when using version 1.15.0.

The trackback shows:

  File "/Users/summer/.cache/pre-commit/reponeoe_8g3/py_env-python3.11/lib/python3.11/site-packages/wrapt/decorators.py", line 34, in <module>
    from inspect import ismethod, isclass, formatargspec
ImportError: cannot import name 'formatargspec' from 'inspect' (/opt/homebrew/Cellar/python@3.11/3.11.4/Frameworks/Python.framework/Versions/3.11/lib/python3.11/inspect.py)

But line 34 in version 1.15.0 (latest) doesn't look like that, so you must be on an older version. See what latest code looks like at:

which should show:

from inspect import isclass
from threading import Lock, RLock

from .arguments import formatargspec

So it doesn't import formatargspec from inspect, but uses a local version.

GrahamDumpleton commented 1 year ago

I would suggest you pip uninstall wrapt and re-install it with latest to make sure is replacing older version.

lilymooncake commented 1 year ago

Thanks, Graham, I did but it still happens and only can be solved by the workaround. However, this ticket can be closed.

GrahamDumpleton commented 1 year ago

If the code doesn't look like what I linked in the GitHub repo, then something is causing you to be pinned to an older version of wrapt.

If you are adamant that the code does match what is in the repo, then run:

pip freeze

and provide the output so can confirm what version pip thinks you have installed.

Also run the Python command line interpreter and from it do:

import wrapt
print(wrapt.__version_info__)

and see what the wrapt package itself says it is. Provide this output as well.

I would not be surprised if you are using some third party package which has pinned to an old version of wrapt and so when you install things it is being force to the old version.