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

version solving mistake with black, tensorflow and typing_extensions. #4516

Closed
2 of 3 tasks
joooeey opened this issue Sep 17, 2021 · 2 comments · Fixed by #4590
Closed
2 of 3 tasks

version solving mistake with black, tensorflow and typing_extensions. #4516

joooeey opened this issue Sep 17, 2021 · 2 comments · Fixed by #4590
Labels
area/solver Related to the dependency resolver kind/bug Something isn't working as expected

Comments

@joooeey
Copy link

joooeey commented Sep 17, 2021

  • I am on the latest Poetry version.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • Linux Mint 20.1:
  • Poetry version 1.1.8:
  • Link of a Gist with the contents of your pyproject.toml file:

Issue

When specifying the dependencies tensorflow and black = "*", poetry doesn't install the correct version of typing_extensions for black which causes an error when running black.

To reproduce, type in terminal:

conda create python=3.9 --name poetry-demo
conda activate poetry-demo
poetry new poetry-demo
cd poetry-demo

Edit pyproject.toml's dependency section:

[tool.poetry.dependencies]
python = "^3.8"
black = "*"
tensorflow = "2.6.0"

Now type in terminal:

poetry install
poetry run black .

The last command results in the following error:

Traceback (most recent call last):
  File "/home/lukas/anaconda3/envs/poetry-demo/bin/black", line 5, in <module>
    from black import patched_main
  File "/home/lukas/anaconda3/envs/poetry-demo/lib/python3.9/site-packages/black/__init__.py", line 48, in <module>
    from black.files import find_project_root, find_pyproject_toml, parse_pyproject_toml
  File "/home/lukas/anaconda3/envs/poetry-demo/lib/python3.9/site-packages/black/files.py", line 26, in <module>
    from black.handle_ipynb_magics import jupyter_dependencies_are_installed
  File "/home/lukas/anaconda3/envs/poetry-demo/lib/python3.9/site-packages/black/handle_ipynb_magics.py", line 15, in <module>
    from typing_extensions import TypeGuard
ImportError: cannot import name 'TypeGuard' from 'typing_extensions' (/home/lukas/anaconda3/envs/poetry-demo/lib/python3.9/site-packages/typing_extensions.py)

This happens because poetry installs black 21.9b0 and typing_extensions 3.7.4.3 although black 21.9b0 requires typing_extensions 3.10.0.0.

Workaround

This issue doesn't occur when the black version is specified to e.g. 21.7b0.

Expected behaviour

The above command sequence should fail early in poetry install instead of the cryptic error when running black. If I change the dependency in pyproject.toml to black "21.9b0", I get the expected behaviour. poetry install fails with:

  SolverProblemError

  Because tensorflow (2.6.0) depends on typing-extensions (>=3.7.4,<3.8.0)
   and black (21.9b0) depends on typing-extensions (>=3.10.0.0), tensorflow (2.6.0) is incompatible with black (21.9b0).
  So, because poetry-demo depends on both black (21.9b0) and tensorflow (2.6.0), version solving failed.

This error should also be reported in the described issue above when I specifiy black = "*".

Or even better, poetry should simply install black 21.7b0 which is compatible with the tensorflow requirement.

@joooeey joooeey added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Sep 17, 2021
@finswimmer finswimmer added the area/solver Related to the dependency resolver label Sep 17, 2021
@radoering
Copy link
Member

It seems to me that poetry can't handle the requirements correctly because black 21.9b0 defines two entries for typing_extensions that are not mutually exclusive (from https://github.com/psf/black/blob/21.9b0/setup.py#L82-L85):

"typing_extensions>=3.10.0.0",
# 3.10.0.1 is broken on at least Python 3.10,
# https://github.com/python/typing/issues/865
"typing_extensions!=3.10.0.1; python_version >= '3.10'",

The first entry applies to all python versions (including >= 3.10), the second entry adds an additional requirement for python 3.10 and above. At least, this seems to be the intention of the author and pip handles it that way: Only the first entry applies for python < 3.10 and both entries apply for python >= 3.10.

However, examining the resulting poetry.lock file, there is an entry for black 21.9b0 containing only the second requirement for typing_extensions. In my understanding, there should also be two entries (for the different python versions) in the lock file.

I tried to resolve the issue in the attached PR.

@abn abn removed the status/triage This issue needs to be triaged label Mar 3, 2022
Copy link

github-actions bot commented Mar 2, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/solver Related to the dependency resolver kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants