tox-dev / filelock

A platform-independent file lock for Python.

Home Page:https://py-filelock.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

asottile opened this issue · comments

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

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

mypy depends on typing-extensions always

Is that true for pyre and co too?

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

PR welcome 👍