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

[Bug] Incorrect reportShadowedImports on Python 3.10 venv and override #4762

Closed
watfordkcf opened this issue Aug 25, 2023 · 5 comments
Closed
Assignees
Labels
needs investigation Could be an issue - needs investigation user responded Was "waiting for user response" and they responded

Comments

@watfordkcf
Copy link

watfordkcf commented Aug 25, 2023

Environment data

  • Language Server version: 2023.8.40
  • OS and version: darwin arm64
  • Python version (and distribution if applicable, e.g. Anaconda): 3.10.11 (pyenv)
  • python.analysis.indexing: true
  • python.analysis.typeCheckingMode: off

Code Snippet

from typing_extensions import override

Repro Steps

  1. I have a Python 3.10 virtual env
  2. I have run pip install typing_extensions to get access to override
  3. I import it as you must in 3.10

Expected behavior

No reportShadowedImports.

Actual behavior

reportShadowedImports on the line:

"/Users/watford/repos/core/.venv/lib/python3.10/site-packages/typing_extensions.py" is overriding the stdlib module "typing_extensions"PylancereportShadowedImports

Logs

...the volume of logs generated was pretty crazy for this monorepo.

@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Aug 25, 2023
@erictraut
Copy link
Contributor

I'm not able to repro the problem with the steps described above. I suspect there's something else needed to repro the problem. Are you able to recreate the error if you start with a clean venv and a clean project? Do you have a local file in your project called typing_extensions.py? Or perhaps you have some non-default extraPaths configured in your project that make pylance think that you have a local typing_extensions.py in your local project?

@watfordkcf
Copy link
Author

Interesting! This is the exact error, my apologies for not including it:

"/Users/watford/repos/core/.venv/lib/python3.10/site-packages/typing_extensions.py" is overriding the stdlib module "typing_extensions" PylancereportShadowedImports

A quick look in the repo doesn't show anything outside the venv with that name:

➜ find . -name "typing_extensions*"
./.mypy_cache/3.10/typing_extensions.meta.json
./.mypy_cache/3.10/typing_extensions.data.json
./.venv/lib/python3.10/site-packages/jedi/third_party/typeshed/third_party/2and3/typing_extensions.pyi
./.venv/lib/python3.10/site-packages/__pycache__/typing_extensions.cpython-310.pyc
./.venv/lib/python3.10/site-packages/typing_extensions-4.7.1.dist-info
./.venv/lib/python3.10/site-packages/pip/_vendor/__pycache__/typing_extensions.cpython-310.pyc
./.venv/lib/python3.10/site-packages/pip/_vendor/typing_extensions.py
./.venv/lib/python3.10/site-packages/mypy/typeshed/stdlib/typing_extensions.pyi
./.venv/lib/python3.10/site-packages/setuptools/_vendor/__pycache__/typing_extensions.cpython-310.pyc
./.venv/lib/python3.10/site-packages/setuptools/_vendor/typing_extensions.py
./.venv/lib/python3.10/site-packages/pkg_resources/_vendor/__pycache__/typing_extensions.cpython-310.pyc
./.venv/lib/python3.10/site-packages/pkg_resources/_vendor/typing_extensions.py
./.venv/lib/python3.10/site-packages/typing_extensions.py

Here is the list of installed packages in that venv:

aiobotocore==2.5.0
aiofiles==22.1.0
aiohttp==3.8.5
aioitertools==0.11.0
aiosignal==1.3.1
aiosmtplib==2.0.2
alembic==1.11.1
altgraph==0.17.3
annotated-types==0.5.0
anyio==3.7.1
apache-airflow==2.5.1
apache-airflow-providers-amazon==7.1.0
apache-airflow-providers-common-sql==1.6.0
apache-airflow-providers-ftp==3.4.2
apache-airflow-providers-http==4.5.0
apache-airflow-providers-imap==3.2.2
apache-airflow-providers-sqlite==3.4.2
apispec==3.3.2
appnope==0.1.3
argcomplete==3.1.1
artifacts-keyring==0.3.3
asgiref==3.7.2
asn1crypto==1.5.1
astroid==2.15.6
asttokens==2.2.1
astunparse==1.6.3
async-timeout==4.0.2
attrs==22.2.0
autoflake==2.0.2
aws-lambda-powertools==2.17.0
azure-core==1.28.0
Babel==2.12.1
backcall==0.2.0
bcrypt==4.0.1
beautifulsoup4==4.12.2
black==23.7.0
blinker==1.6.2
boto3==1.26.34
boto3-stubs==1.28.32
botocore==1.29.76
botocore-stubs==1.31.6
Bottleneck==1.3.7
cachelib==0.9.0
cattrs==23.1.2
certifi==2023.7.22
cffi==1.15.1
charset-normalizer==2.1.1
click==8.1.6
clickclick==20.10.2
colorama==0.4.6
colorlog==4.8.0
ConfigUpdater==3.1.1
connexion==2.14.2
contextlib2==21.6.0
contourpy==1.1.0
cron-descriptor==1.4.0
croniter==1.4.1
cryptography==41.0.2
cycler==0.11.0
dataclasses-json==0.5.12
decorator==5.1.1
defusedxml==0.7.1
delta-spark==2.4.0
Deprecated==1.2.14
dill==0.3.6
dnspython==2.4.0
docutils==0.20.1
email-validator==1.3.1
et-xmlfile==1.1.0
exceptiongroup==1.1.2
executing==1.2.0
faiss-cpu==1.7.4
fastapi==0.100.0
flake8==6.0.0
flake8-print==5.0.0
Flake8-pyproject==1.2.3
Flask==2.2.5
Flask-AppBuilder==4.1.4
Flask-Babel==2.0.0
Flask-Caching==2.0.2
Flask-JWT-Extended==4.5.2
Flask-Login==0.6.2
Flask-Session==0.5.0
Flask-SQLAlchemy==2.5.1
Flask-WTF==1.1.1
fonttools==4.41.0
fpdf==1.7.2
frozenlist==1.4.0
fsspec==2023.6.0
future-fstrings==1.2.0
gitdb==4.0.10
GitPython==3.1.32
google-pasta==0.2.0
graphviz==0.20.1
gunicorn==21.2.0
h11==0.14.0
httpcore==0.17.3
httpx==0.24.1
hypothesis==6.82.6
idna==3.4
imbalanced-learn==0.11.0
importlib-metadata==4.13.0
inflection==0.5.1
iniconfig==2.0.0
ipython==8.14.0
isodate==0.6.1
isort==5.12.0
itsdangerous==2.1.2
jaraco.classes==3.3.0
jedi==0.18.2
Jinja2==3.1.2
jmespath==1.0.1
joblib==1.3.1
JSON-log-formatter==0.5.1
jsonpath-ng==1.5.3
jsonschema==4.18.4
jsonschema-specifications==2023.7.1
keyring==24.2.0
kiwisolver==1.4.4
langsmith==0.0.10
lark==1.1.7
lazy-object-proxy==1.9.0
linkify-it-py==2.0.2
llvmlite==0.40.1
lockfile==0.12.2
lxml==4.9.3
macholib==1.16.2
Mako==1.2.4
mangum==0.17.0
Markdown==3.4.3
markdown-it-py==3.0.0
MarkupSafe==2.1.3
marshmallow==3.19.0
marshmallow-enum==1.5.1
marshmallow-oneofschema==3.0.1
marshmallow-sqlalchemy==0.26.1
matplotlib==3.7.2
matplotlib-inline==0.1.6
mccabe==0.7.0
mdit-py-plugins==0.4.0
mdurl==0.1.2
more-itertools==9.1.0
msrest==0.7.1
multidict==6.0.4
multiprocess==0.70.14
mypy==1.5.1
mypy-boto3-appflow==1.28.0
mypy-boto3-athena==1.28.0
mypy-boto3-emr-serverless==1.28.0
mypy-boto3-mwaa==1.28.0
mypy-boto3-rds==1.28.0
mypy-boto3-redshift-data==1.28.0
mypy-boto3-s3==1.28.3.post2
mypy-boto3-sagemaker==1.28.3.post2
mypy-boto3-sagemaker-runtime==1.28.0
mypy-boto3-secretsmanager==1.28.3.post2
mypy-boto3-ssm==1.28.0
mypy-extensions==1.0.0
mypy-typing-asserts==0.1.1
nest-asyncio==1.5.6
networkx==3.1
nltk==3.8.1
numexpr==2.8.4
numpy==1.25.2
oauthlib==3.2.2
odfpy==1.4.1
openai==0.27.8
openapi-schema-pydantic==1.2.4
openpyxl==3.1.2
packaging==23.0
paho-mqtt==1.6.1
pandas==2.0.1
pandas-stubs==2.0.3.230814
paramiko==3.0.0
parso==0.8.3
pathos==0.3.0
pathspec==0.9.0
pendulum==2.1.2
pexpect==4.8.0
pickleshare==0.7.5
Pillow==10.0.0
platformdirs==3.9.1
pluggy==1.2.0
ply==3.11
pox==0.3.2
ppft==1.7.6.6
prison==0.2.1
progressbar2==4.2.0
prompt-toolkit==3.0.39
protobuf==3.20.3
protobuf3-to-dict==0.1.5
psutil==5.9.5
psycopg==3.1.9
psycopg-binary==3.1.9
psycopg2-binary==2.9.6
ptyprocess==0.7.0
pure-eval==0.2.2
py4j==0.10.9.7
pyarrow==11.0.0
pycodestyle==2.10.0
pycparser==2.21
pydantic==1.10.11
pyflakes==3.0.1
Pygments==2.15.1
pyinstaller==5.13.0
pyinstaller-hooks-contrib==2023.5
PyJWT==2.8.0
pylint==2.17.5
PyNaCl==1.5.0
pyparsing==3.0.9
PyPDF2==3.0.1
pyspark==3.4.0
pytest==7.4.0
pytest-depends==1.0.1
pytest-mock==3.11.1
python-daemon==3.0.1
python-dateutil==2.8.2
python-docx==0.8.11
python-hcl2==4.3.2
python-nvd3==0.15.0
python-pptx==0.6.21
python-slugify==8.0.1
python-utils==3.7.0
pytz==2023.3
pytzdata==2020.1
PyWavelets==1.4.1
pyxlsb==1.0.10
PyYAML==6.0.1
redis==4.5.1
redshift-connector==2.0.913
referencing==0.30.0
regex==2023.6.3
requests==2.28.1
requests-futures==1.0.1
requests-oauthlib==1.3.1
requests-toolbelt==1.0.0
rich==13.4.2
rpds-py==0.9.2
s3fs==2023.6.0
s3transfer==0.6.1
sagemaker==2.142.0
schema==0.7.5
scikit-learn==1.2.1
scipy==1.10.0
scramp==1.4.4
seaborn==0.12.2
semver==2.13.0
setproctitle==1.3.2
six==1.16.0
smdebug-rulesconfig==1.0.1
smmap==5.0.0
sniffio==1.3.0
sortedcontainers==2.4.0
soupsieve==2.4.1
SQLAlchemy==1.4.49
SQLAlchemy-JSONField==1.0.1.post0
sqlalchemy-redshift==0.8.14
SQLAlchemy-Utils==0.41.1
sqlparse==0.4.4
sshtunnel==0.4.0
stack-data==0.6.2
starlette==0.27.0
swagger-ui-bundle==0.0.9
tabulate==0.9.0
tenacity==8.2.2
termcolor==2.3.0
text-unidecode==1.3
threadpoolctl==3.2.0
tiktoken==0.4.0
toml==0.10.2
tomli==2.0.1
tomlkit==0.11.8
tqdm==4.65.0
traitlets==5.9.0
typed-ast==1.5.5
typed-astunparse==2.1.4
types-aiobotocore==2.6.0
types-aiobotocore-cloudformation==2.6.0
types-aiobotocore-dynamodb==2.6.0
types-aiobotocore-ec2==2.6.0
types-aiobotocore-kinesis==2.5.2
types-aiobotocore-lambda==2.6.0
types-aiobotocore-rds==2.6.0
types-aiobotocore-s3==2.6.0
types-aiobotocore-sagemaker-runtime==2.5.2
types-aiobotocore-sqs==2.6.0
types-aiobotocore-sts==2.5.2
types-aiofiles==23.2.0.0
types-awscrt==0.16.26
types-boto3==1.0.2
types-botocore==1.0.2
types-paramiko==3.3.0.0
types-Pillow==10.0.0.2
types-psycopg2==2.9.21.11
types-pyOpenSSL==23.2.0.1
types-python-dateutil==2.8.19.14
types-pytz==2023.3.0.0
types-PyYAML==6.0.12.11
types-redis==4.6.0.5
types-requests==2.31.0.2
types-s3transfer==0.6.1
types-setuptools==68.1.0.0
types-toml==0.10.8.7
types-typed-ast==1.5.8.7
types-urllib3==1.26.25.13
typing-inspect==0.9.0
typing_extensions==4.7.1
tzdata==2023.3
uc-micro-py==1.0.2
unicodecsv==0.14.1
urllib3==1.26.16
uvicorn==0.23.1
version-query==1.4.0
watchtower==2.0.1
wcwidth==0.2.6
Werkzeug==2.2.3
wrapt==1.15.0
WTForms==3.0.1
xgboost==1.7.1
xlrd==2.0.1
XlsxWriter==3.1.2
yarl==1.9.2
zipp==3.16.2

@watfordkcf
Copy link
Author

watfordkcf commented Aug 25, 2023

Another note:

  1. I could not recreate this in a brand new project with a clean venv
  2. I could not recreate this in a brand new project with a clean venv with that exact set of requirements
  3. I could recreate this in a brand new project, clean venv, that set of requirements, after adding the following pyproject.toml:
# minimum reproduction
[tool.pyright]
exclude = [
    "**/__pycache__/**"
]
image

@heejaechang
Copy link
Contributor

@watfordkcf

that's probably because you added explicit exclude. due to that, pylance no longer do auto exclude

my guess is due to that, now /Users/watford/repos/core/.venv/ is considered part of your workspace not site-packages so, the error shows up.

try adding **/.venv to your explicit exclude so pylance don't consider them as part of your workspace.

@heejaechang heejaechang added waiting for user response Requires more information from user needs investigation Could be an issue - needs investigation and removed needs repro Issue has not been reproduced yet labels Aug 28, 2023
@watfordkcf
Copy link
Author

watfordkcf commented Aug 28, 2023

That certainly seems to work! Thank you.

EDIT: Though it would be nice that the currently selected virtual environment was excluded by Pylance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs investigation Could be an issue - needs investigation user responded Was "waiting for user response" and they responded
Projects
None yet
Development

No branches or pull requests

3 participants