python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.48k stars 2.83k forks source link

FixtureFunction TypeVar pollutes mypy annotations for arbitrary types #17673

Closed pechersky closed 2 months ago

pechersky commented 3 months ago

Bug Report

(A clear and concise description of what the bug is.)

To Reproduce

I have pytest-asyncio and requests installed in my python environment, with mypy==1.11.1. I use VSCode as my IDE. Once I installed pytest-asyncio, the inferred type annotations for many things got much more complex, and now say: FixtureFunction[SimpleFixtureFunction@FixtureFunction, FactoryFixtureFunction@FixtureFunction] I also think these catch-all typevars end up slowing down the mypy typechecking, but that's only a guess.

Here is an example (sorry for the screenshot, not sure how to get command line output to display this): image Uninstalling and then reinstalling pytest-asyncio seems to have resolved the issue, but colleagues have this issue too when they start new environments.

cf: https://github.com/pytest-dev/pytest-asyncio/issues/919

Expected Behavior

In this example, I would expect to see the function arguments be Any | None = None

Actual Behavior

Even outside of this simple example, many types were aberrantly annotated as this FixtureFunction before my uninstall/reinstall.

Your Environment

Package                                   Version         Editable project location
----------------------------------------- --------------- ------------------------------
aioboto3                                  13.1.1
aiobotocore                               2.13.1
aiofiles                                  24.1.0
aiohappyeyeballs                          2.3.5
aiohttp                                   3.10.2
aioitertools                              0.11.0
aiosignal                                 1.3.1
alabaster                                 0.7.13
amazon-dax-client                         2.0.3
annotated-types                           0.7.0
antlr4-python3-runtime                    4.9.3
anyio                                     4.4.0
arrow                                     1.3.0
asgiref                                   3.8.1
async-timeout                             4.0.3
attrs                                     23.2.0
aws-lambda-typing                         2.20.0
Babel                                     2.12.1
backoff                                   2.2.1
binaryornot                               0.4.4
black                                     24.8.0
boto3                                     1.34.131
boto3-stubs                               1.34.153
botocore                                  1.34.131
botocore-stubs                            1.34.138
Cerberus                                  1.3.5
certifi                                   2024.7.4
cfgv                                      3.4.0
chardet                                   5.2.0
charset-normalizer                        3.3.2
click                                     8.1.7
cookiecutter                              2.6.0
coverage                                  7.5.4
cruft                                     2.15.0
darglint                                  1.8.1
Deprecated                                1.2.14
distlib                                   0.3.8
dnspython                                 2.6.1
docopt                                    0.6.2
docstring_parser_fork                     0.0.2
docutils                                  0.20.1
email_validator                           2.1.1
exceptiongroup                            1.2.1
fastapi                                   0.112.0
fastapi-cli                               0.0.2
fastapi-utils                             0.2.1
filelock                                  3.15.4
flake8                                    7.1.1
flake8-docstrings                         1.7.0
frozenlist                                1.4.1
gitdb                                     4.0.11
GitPython                                 3.1.43
googleapis-common-protos                  1.63.2
greenlet                                  2.0.2
grpcio                                    1.64.1
gunicorn                                  23.0.0
h11                                       0.14.0
httpcore                                  1.0.5
httptools                                 0.6.1
httpx                                     0.27.0
identify                                  2.5.36
idna                                      3.7
imagesize                                 1.4.1
immutabledict                             4.2.0
importlib-metadata                        6.11.0
iniconfig                                 2.0.0
isort                                     5.13.2
Jinja2                                    3.1.4
jmespath                                  1.0.1
jsonmerge                                 1.9.2
jsonschema                                4.22.0
jsonschema-specifications                 2023.12.1
kuva                                      1.0.0
line_profiler                             4.1.3
markdown-it-py                            3.0.0
MarkupSafe                                2.1.5
mccabe                                    0.7.0
mdurl                                     0.1.2
mirakuru                                  2.5.2
more-itertools                            10.4.0
multidict                                 6.0.5
mypy                                      1.11.1
mypy-boto3-dax                            1.34.0
mypy-boto3-dynamodb                       1.34.131
mypy-extensions                           1.0.0
nodeenv                                   1.9.1
numpydoc                                  1.5.0
OpenEye-client-utils                      0.6.2.post1
OpenEye-maas-apps                         0.13.13
OpenEye-maas-apps-linux-x64               0.13.13
OpenEye-maasclient                        1.1.0
OpenEye-toolkits                          2023.1.1
OpenEye-toolkits-python3-linux-x64        2023.1.1
opentelemetry-api                         1.20.0
opentelemetry-distro                      0.41b0
opentelemetry-exporter-otlp               1.20.0
opentelemetry-exporter-otlp-proto-common  1.20.0
opentelemetry-exporter-otlp-proto-grpc    1.20.0
opentelemetry-exporter-otlp-proto-http    1.20.0
opentelemetry-instrumentation             0.41b0
opentelemetry-instrumentation-asgi        0.41b0
opentelemetry-instrumentation-aws-lambda  0.41b0
opentelemetry-instrumentation-boto        0.41b0
opentelemetry-instrumentation-boto3sqs    0.41b0
opentelemetry-instrumentation-botocore    0.41b0
opentelemetry-instrumentation-dbapi       0.41b0
opentelemetry-instrumentation-fastapi     0.41b0
opentelemetry-instrumentation-logging     0.41b0
opentelemetry-instrumentation-psycopg2    0.41b0
opentelemetry-instrumentation-requests    0.41b0
opentelemetry-instrumentation-sqlalchemy  0.41b0
opentelemetry-instrumentation-sqlite3     0.41b0
opentelemetry-instrumentation-tortoiseorm 0.41b0
opentelemetry-instrumentation-urllib      0.41b0
opentelemetry-instrumentation-urllib3     0.41b0
opentelemetry-instrumentation-wsgi        0.41b0
opentelemetry-propagator-aws-xray         1.0.1
opentelemetry-proto                       1.20.0
opentelemetry-sdk                         1.20.0
opentelemetry-sdk-extension-aws           2.0.1
opentelemetry-semantic-conventions        0.41b0
opentelemetry-util-http                   0.41b0
orjson                                    3.10.3
packaging                                 24.1
parsy                                     2.1
pathspec                                  0.12.1
pep517                                    0.13.1
pip                                       23.3.1
pip-api                                   0.0.30
pipreqs                                   0.4.13
platformdirs                              4.2.2
plette                                    0.4.4
pluggy                                    1.5.0
port-for                                  0.7.2
pre-commit                                3.8.0
protobuf                                  4.25.3
psutil                                    6.0.0
psycopg                                   3.2.1
psycopg2                                  2.9.9
psycopg2-binary                           2.9.9
pycodestyle                               2.12.0
pydantic                                  2.8.0
pydantic_core                             2.20.0
pydoclint                                 0.2.4
pydocstyle                                6.3.0
pyflakes                                  3.2.0
Pygments                                  2.18.0
pyinstrument                              4.7.2
pyrsistent                                0.19.3
pytest                                    8.3.2
pytest-asyncio                            0.23.8
pytest-cov                                5.0.0
pytest-dynamodb                           2.2.3.post3
pytest-httpx                              0.23.1
pytest-mock                               3.14.0
pytest-postgresql                         6.0.0
python-dateutil                           2.9.0.post0
python-dotenv                             1.0.1
python-multipart                          0.0.9
python-slugify                            8.0.4
PyYAML                                    6.0.1
referencing                               0.35.1
requests                                  2.32.3
requests-toolbelt                         1.0.0
requirementslib                           3.0.0
responses                                 0.25.3
rich                                      13.7.1
rpds-py                                   0.18.1
s3transfer                                0.10.2
sendoff                                   0.1.6
setuptools                                70.2.0
shellingham                               1.5.4
six                                       1.16.0
smmap                                     5.0.1
sniffio                                   1.3.1
snowballstemmer                           2.2.0
Sphinx                                    7.2.3
sphinxcontrib-applehelp                   1.0.7
sphinxcontrib-devhelp                     1.0.5
sphinxcontrib-htmlhelp                    2.0.4
sphinxcontrib-jsmath                      1.0.1
sphinxcontrib-qthelp                      1.0.6
sphinxcontrib-serializinghtml             1.1.9
SQLAlchemy                                2.0.19
SQLAlchemy-Utils                          0.41.1
sqlparse                                  0.5.0
starlette                                 0.37.2
tabulate                                  0.9.0
text-unidecode                            1.3
tl-chem-queries                           0.3.0
tl-compound-ids                           1.1.0
tl-vtlb-sdk                               0.6.3
tomli                                     2.0.1
tomlkit                                   0.12.3
typer                                     0.12.3
types-aioboto3                            13.1.1
types-aiobotocore                         2.13.2
types-aiobotocore-dynamodb                2.13.2
types-awscrt                              0.20.12
types-psycopg2                            2.9.21.20240417
types-python-dateutil                     2.9.0.20240316
types-PyYAML                              6.0.12.12
types-requests                            2.32.0.20240712
types-s3transfer                          0.10.1
types-urllib3                             1.26.25.14
typing_extensions                         4.12.2
ujson                                     5.9.0
urllib3                                   2.2.2
urllib3-mock                              0.3.3
uvicorn                                   0.30.5
uvloop                                    0.19.0
virtualenv                                20.26.3
wasmer                                    1.2.0
wasmer_compiler_cranelift                 1.2.0
watchfiles                                0.22.0
websockets                                12.0
wheel                                     0.38.4
wrapt                                     1.16.0
yarg                                      0.1.9
yarl                                      1.9.4
yaspin                                    0.14.3
yoyo-migrations                           8.2.0
zipp                                      3.19.2
przemoch-dev commented 3 months ago

Same issue here

speksen-kb01 commented 3 months ago

I have a similar issue with VSCode. But I am using pyright. I haven't configured an explicit linter. I think pyright can be the default linter, and if you haven't configured an explicit linter, when you hover over the types, pyright is the one populating those types you see. Might be a vscode or pyright issue as well

pechersky commented 3 months ago

Seems like the issue is being tracked here: https://github.com/microsoft/pyright/discussions/8608

hauntsaninja commented 2 months ago

I think this is unrelated to mypy, is issue with pylance / pyright

munimdev commented 1 month ago

Upgrading to the latest Pylance version helped solved this issue for me!