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

typing-extensions is a dependency but is not needed at runtime #275

Closed
asottile opened this issue Sep 11, 2023 · 5 comments · Fixed by #276
Closed

typing-extensions is a dependency but is not needed at runtime #275

asottile opened this issue Sep 11, 2023 · 5 comments · Fixed by #276

Comments

@asottile
Copy link
Contributor

I believe it should be a dev-only or typing-only dependency and not needed at runtime -- for example:

$ virtualenv venv -ppython3.8
created virtual environment CPython3.8.18.final.0-64 in 467ms
  creator CPython3Posix(dest=/tmp/venv, clear=False, no_vcs_ignore=False, global=False)
  seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/asottile/.local/share/virtualenv)
    added seed packages: pip==23.1.2, setuptools==68.0.0, wheel==0.40.0
  activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
asottile@babibox2:/tmp
$ . venv/bin/activate
$ pip install filelock
Collecting filelock
  Using cached filelock-3.12.3-py3-none-any.whl (11 kB)
Collecting typing-extensions>=4.7.1 (from filelock)
  Using cached typing_extensions-4.7.1-py3-none-any.whl (33 kB)
Installing collected packages: typing-extensions, filelock
Successfully installed filelock-3.12.3 typing-extensions-4.7.1
$ pip uninstall typing-extensions
Found existing installation: typing_extensions 4.7.1
Uninstalling typing_extensions-4.7.1:
  Would remove:
    /tmp/venv/lib/python3.8/site-packages/typing_extensions-4.7.1.dist-info/*
    /tmp/venv/lib/python3.8/site-packages/typing_extensions.py
Proceed (Y/n)? y
  Successfully uninstalled typing_extensions-4.7.1
$ python3 -c 'import filelock'

it is only "needed" in TYPE_CHECKING mode:

$ python3 -c 'import typing; typing.TYPE_CHECKING = True; import filelock'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/venv/lib/python3.8/site-packages/filelock/__init__.py", line 14, in <module>
    from ._api import AcquireReturnProxy, BaseFileLock
  File "/tmp/venv/lib/python3.8/site-packages/filelock/_api.py", line 22, in <module>
    from typing_extensions import Self
ModuleNotFoundError: No module named 'typing_extensions'

but a type checker isn't going to actually "import" it

@gaborbernat
Copy link
Member

Yeah, but mypy would fail without this dependency, unless the user does pip install filelock[type] which is bit hard to discover.

@asottile
Copy link
Contributor Author

mypy depends on typing-extensions always

@gaborbernat
Copy link
Member

Is that true for pyre and co too?

@asottile
Copy link
Contributor Author

I checked pyre (pulls it in as a dependency) and pyright (has it through typeshed and analyzer specializations)

@gaborbernat
Copy link
Member

PR welcome 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants