pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.29k stars 1.13k forks source link

ImportError: cannot import name 'Self' from 'typing_extensions' with astroid 2.13.2 #8035

Closed fly50789 closed 1 year ago

fly50789 commented 1 year ago

Bug description

error:

ImportError: cannot import name 'Self' from 'typing_extensions'

with astroid==2.13.2

I use tox to run pylint command.

And After I use astroid==2.12.13 can fix this bug.

tox setting

[testenv:linting]
description = linting test
# cant skip install
skip_install = False
deps = pylint
       astroid==2.12.13
commands =
           pylint --rcfile=tox.ini src

Configuration

No response

Command used

pylint --rcfile=tox.ini src

Pylint output

linting: commands[0]> pylint --rcfile=tox.ini src
Traceback (most recent call last):
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/bin/pylint", line 8, in <module>
    sys.exit(run_pylint())
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/pylint/__init__.py", line 32, in run_pylint
    from pylint.lint import Run as PylintRun
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/pylint/lint/__init__.py", line 19, in <module>
    from pylint.config.exceptions import ArgumentPreprocessingError
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/pylint/config/__init__.py", line 25, in <module>
    from pylint.config.arguments_provider import UnsupportedAction
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/pylint/config/arguments_provider.py", line 15, in <module>
    from pylint.config.arguments_manager import _ArgumentsManager
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/pylint/config/arguments_manager.py", line 25, in <module>
    from pylint import utils
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/pylint/utils/__init__.py", line 9, in <module>
    from pylint.utils.ast_walker import ASTWalker
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/pylint/utils/ast_walker.py", line 13, in <module>
    from astroid import nodes
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/astroid/__init__.py", line 46, in <module>
    from astroid import inference, raw_building
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/astroid/inference.py", line 18, in <module>
    from astroid import bases, constraint, decorators, helpers, nodes, protocols, util
  File "/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/astroid/constraint.py", line 19, in <module>
    from typing_extensions import Self
ImportError: cannot import name 'Self' from 'typing_extensions' (/home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/linting/lib/python3.8/site-packages/typing_extensions.py)
linting: exit 1 (0.75 seconds) /home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter> pylint --rcfile=tox.ini src pid=30684
.pkg: _exit> python /home/gitlab-runner/.local/lib/python3.8/site-packages/pyproject_api/_backend.py True setuptools.build_meta
  linting: FAIL code 1 (137.49=setup[136.74]+cmd[0.75] seconds)
  evaluation failed :( (138.27 seconds)

Expected behavior

normal run

Pylint version

pylint==2.15.9
astroid==2.13.2
python 3.8.0

OS / Environment

Linux

Additional dependencies

No response

Pierre-Sassoulas commented 1 year ago

Thank you for opening the issue. What is your local version of typing-extensions ? With astroid 2.13.2 it should be >= 4.0.0 (https://github.com/PyCQA/astroid/blob/f717084fea5ba9c030b7a8fe08336b7ee7b66b64/pyproject.toml#L39).

fly50789 commented 1 year ago

typing-extensions==3.10.0.0

ps. pass and fail has same typing-extensions version

only difference is astroid==2.13.2(Fail) and astroid==2.12.13(Pass)

all pkg version of fail pylint

linting: freeze> python -m pip freeze --all
linting: aniso8601==9.0.1,asgiref==3.4.1,astroid==2.12.13,atomicwrites==1.4.0,attrs==21.2.0,bcj-cffi==0.5.1,bcrypt==3.2.0,beautifulsoup4==4.9.3,bidict==0.21.2,Brotli==1.0.9,bs4==0.0.1,certifi==2021.5.30,cffi==1.14.5,charset-normalizer==2.0.3,click==7.1.2,color-it==2.1.3,colorama==0.4.4,coreapi==2.3.3,coreschema==0.0.4,coverage==6.3.2,cryptography==3.4.7,cycler==0.11.0,decorator==5.0.9,defusedxml==0.7.1,dill==0.3.6,Django==3.2.7,djangorestframework==3.12.4,dnspython==2.1.0,drf-yasg==1.20.0,eventlet==0.33.0,Flask==1.1.2,Flask-Cors==3.0.10,Flask-Login==0.5.0,Flask-RESTful==0.3.9,flask-restful-swagger-2==0.35,flask-restplus==0.13.0,Flask-SocketIO==4.3.1,Flask-SQLAlchemy==2.5.1,flask-swagger-ui==3.36.0,fonttools==4.28.5,future==0.18.2,greenlet==1.1.0,humanize==3.11.0,idna==3.2,importlib-metadata==4.3.1,inflection==0.5.1,iniconfig==1.1.1,iso8601==1.0.2,isort==5.11.4,itsdangerous==1.1.0,itypes==1.2.0,jeepney==0.8.0,Jinja2==2.11.3,jira==3.0.1,jsonschema==3.2.0,keyring==23.1.0,kiwisolver==1.3.2,lazy-object-proxy==1.9.0,ldap3==2.9,lxml==4.6.3,lz4==3.1.3,MarkupSafe==1.1.1,matplotlib==3.5.1,mccabe==0.7.0,multivolumefile==0.2.3,numpy==1.21.1,oauthlib==3.1.1,packaging==21.0,paramiko==2.7.2,Pillow==8.4.0,pip==22.3.1,platformdirs==2.6.2,pluggy==0.13.1,pretty-cron==1.2.0,psutil==5.8.0,py==1.10.0,py7zr==0.16.1,pyasn1==0.4.8,PyContracts==1.8.12,pycparser==2.20,pycryptodomex==3.10.1,pylint==2.15.9,PyMySQL==1.0.2,PyNaCl==1.4.0,pyOpenSSL==20.0.1,pyparsing==2.4.7,pyppmd==0.16.1,pyrsistent==0.18.0,pyserial==3.5,pytest==6.2.4,pytest-cov==3.0.0,python-dateutil==2.8.2,python-engineio==3.13.2,python-socketio==4.6.0,pytz==2021.1,pywin32-ctypes==0.2.0,PyYAML==5.4.1,pyzstd==0.14.4,reportlab==3.6.1,requests==2.26.0,requests-oauthlib==1.3.0,requests-toolbelt==0.9.1,robotbackgroundlogger==1.2,robotframework==4.1.1,ruamel.yaml==0.17.16,ruamel.yaml.clib==0.2.6,SecretStorage==3.3.3,setuptools==65.6.3,six==1.16.0,soupsieve==2.2.1,SQLAlchemy==1.4.17,sqlparse==0.4.2,Starter-Package @ file:///home/gitlab-runner/builds/yrhbVoRw/1/5g-o-ran/system-verification/tia/starter/.tox/.tmp/package/1/Starter-Package-2023.1.0b2.tar.gz,texttable==1.6.4,toml==0.10.2,tomli==2.0.1,tomlkit==0.11.6,typing-extensions==3.10.0.0,uritemplate==3.0.1,urllib3==1.26.6,Werkzeug==0.16.1,wheel==0.38.4,wrapt==1.14.1,WTForm==1.0,zipp==3.4.1
linting: commands[0]> pylint --rcfile=tox.ini src
Pierre-Sassoulas commented 1 year ago

I'm not sure why you're typing extensions was not upgraded to 4.0.0 or superior when installing astroid 2.13.2 but it should according to the metadata we provide when packaging astroid. Could you try to upgrade typing-extensions manually ?

fly50789 commented 1 year ago

@Pierre-Sassoulas I use tox and manual to install pylint in venv and share same result.

(.venv) C:\Users\pega_user\Desktop\vs_project\other\ex3>pip freeze
astroid==2.13.2
colorama==0.4.6
dill==0.3.6
isort==5.11.4
lazy-object-proxy==1.9.0
mccabe==0.7.0
platformdirs==2.6.2
pylint==2.15.9
tomli==2.0.1
tomlkit==0.11.6
typing-extensions==4.4.0
wrapt==1.14.1

But after I set tox to install my pkg.

Sorry I dont know how pip to resolve Its dependence. Please tell me how to maintain its dependence if you know.

aniso8601==9.0.1
asgiref==3.4.1
astroid==2.13.2
atomicwrites==1.4.0
attrs==21.2.0
bcj-cffi==0.5.1
bcrypt==3.2.0
beautifulsoup4==4.9.3
bidict==0.21.2
Brotli==1.0.9
bs4==0.0.1
certifi==2021.5.30
cffi==1.14.5
charset-normalizer==2.0.3
click==7.1.2
color-it==2.1.3
colorama==0.4.4
coreapi==2.3.3
coreschema==0.0.4
coverage==6.3.2
cryptography==3.4.7
cycler==0.11.0
decorator==5.0.9
defusedxml==0.7.1
dill==0.3.6
Django==3.2.7
djangorestframework==3.12.4
dnspython==2.1.0
drf-yasg==1.20.0
eventlet==0.33.0
Flask==1.1.2
Flask-Cors==3.0.10
Flask-Login==0.5.0
Flask-RESTful==0.3.9
flask-restful-swagger-2==0.35
flask-restplus==0.13.0
Flask-SocketIO==4.3.1
Flask-SQLAlchemy==2.5.1
flask-swagger-ui==3.36.0
fonttools==4.28.5
future==0.18.2
greenlet==1.1.0
humanize==3.11.0
idna==3.2
importlib-metadata==4.3.1
inflection==0.5.1
iniconfig==1.1.1
iso8601==1.0.2
isort==5.11.4
itsdangerous==1.1.0
itypes==1.2.0
Jinja2==2.11.3
jira==3.0.1
jsonschema==3.2.0
keyring==23.1.0
kiwisolver==1.3.2
lazy-object-proxy==1.9.0
ldap3==2.9
lxml==4.6.3
lz4==3.1.3
MarkupSafe==1.1.1
matplotlib==3.5.1
mccabe==0.7.0
multivolumefile==0.2.3
numpy==1.21.1
oauthlib==3.1.1
packaging==21.0
paramiko==2.7.2
Pillow==8.4.0
platformdirs==2.6.2
pluggy==0.13.1
pretty-cron==1.2.0
psutil==5.8.0
py==1.10.0
py7zr==0.16.1
pyasn1==0.4.8
PyContracts==1.8.12
pycparser==2.20
pycryptodomex==3.10.1
pylint==2.15.9
PyMySQL==1.0.2
PyNaCl==1.4.0
pyOpenSSL==20.0.1
pyparsing==2.4.7
pyppmd==0.16.1
pyrsistent==0.18.0
pyserial==3.5
pytest==6.2.4
pytest-cov==3.0.0
python-dateutil==2.8.2
python-engineio==3.13.2
python-socketio==4.6.0
pytz==2021.1
pywin32-ctypes==0.2.0
PyYAML==5.4.1
pyzstd==0.14.4
reportlab==3.6.1
requests==2.26.0
requests-oauthlib==1.3.0
requests-toolbelt==0.9.1
robotbackgroundlogger==1.2
robotframework==4.1.1
ruamel.yaml==0.17.16
ruamel.yaml.clib==0.2.6
six==1.16.0
soupsieve==2.2.1
SQLAlchemy==1.4.17
sqlparse==0.4.2
-e git+ssh://git@oran-git.pegatroncorp.com/5g-o-ran/system-verification/tia/starter.git@7671ea4e9d6ecb9f55021c99d37555834fd4dcc2#egg=Starter_Package
texttable==1.6.4
toml==0.10.2
tomli==2.0.1
tomlkit==0.11.6
typing-extensions==3.10.0.0
uritemplate==3.0.1
urllib3==1.26.6
Werkzeug==0.16.1
wrapt==1.14.1
WTForm==1.0
zipp==3.4.1
Pierre-Sassoulas commented 1 year ago

There's probably a package requiring typing-extensions < 4 in your dependencies and there's a problem during dependencies resolution. Maybe this package is in fact following semver too restrictively and is cmpatible with 4 or more. Try that, then if that does not work you need to keep astroid in old version or wait for a compatible version of the other package.

fly50789 commented 1 year ago

@Pierre-Sassoulas Thanks your support!!