Poetry's solver rejects installation of pytype in a project supporting Python 3.6+, even though pytype's Python constraint is compatible with it.
Repro:
[tool.poetry]
name = "foobar"
version = "0.1.0"
description = ""
authors = ["User <[email protected]>"]
[tool.poetry.dependencies]
python = "^3.6"
[tool.poetry.dev-dependencies]
[build-system]
requires = ["poetry>=0.12"]
build-backend = "poetry.masonry.api"
poetry add --dev --python="<3.8" pytypeThis results in the following error message:
Creating virtualenv poetry-pytype-VZF4hhnk-py3.7 in ~/Library/Caches/pypoetry/virtualenvs
Using version ^2020.2.20 for pytype
Updating dependencies
Resolving dependencies... (0.0s)
[SolverProblemError]
The current project's Python requirement (^3.6) is not compatible with some of the required packages Python requirement:
- pytype requires Python !=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<3.8,>=2.7
Because no versions of pytype match >2020.2.20,<2021.0.0
and pytype (2020.2.20) requires Python !=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,<3.8,>=2.7, pytype is forbidden.
So, because poetry-pytype depends on pytype (^2020.2.20), version solving failed.
The same error happens with the command poetry add --dev pytype. (The --python="<3.8" was added because pytype currently does not support Python 3.8.)
pytype 2020.2.20 added the following python_requires declaration:
python_requires = >=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, <3.8
IIUC, Poetry refuses to install pytype because the root project declares compatibility with Python ^3.6. This includes 3.8 and up, which would not be supported by pytype. Poetry does not care that we only install pytype in environments with Python < 3.8, using the --python option to poetry add.
It seems, when determining compatibility of Python version constraints, Poetry does not take into account which Python versions a dependency is installed for.
Adding an explicit >=3.6 works:
$ poetry add --dev --python=">=3.6,<3.8" pytype
Using version ^2020.2.20 for pytype
...
So I guess Poetry did pick up the <3.8 constraint earlier. However, Poetry appears to assume that pytype is also being installed for older Python versions such as 3.4, unsupported by pytype.
Since the root package already requires Python ^3.6, Poetry should be able to work out that pytype cannot possibly be installed in an environment violating the Python version constraint.
Same bug (?) for new pytype version 2020.7.30 and python 3.8.3:
poetry add --dev pytype
Using version ^2020.7.30 for pytype
Updating dependencies
Resolving dependencies... (0.8s)
[SolverProblemError]
The current project's Python requirement (^3.8) is not compatible with some of the required packages Python requirement:
- pytype requires Python <3.9,>=3.5
Because no versions of pytype match >2020.7.30,<2021.0.0
and pytype (2020.7.30) requires Python <3.9,>=3.5, pytype is forbidden.
This seem to work:
poetry add --dev --python=3.8 pytype
Using version ^2020.7.30 for pytype
Updating dependencies
Resolving dependencies... (1.7s)
Writing lock file
Package operations: 0 installs, 1 update, 0 removals
- Updating cffi (1.14.0 -> 1.14.1)
It's not a bug, it's a feature ;) and @cjolowicz is on the right track.
See my comment in https://github.com/python-poetry/poetry/issues/1930#issuecomment-653906544 for more details.
fin swimmer
Most helpful comment
Adding an explicit
>=3.6works:So I guess Poetry did pick up the
<3.8constraint earlier. However, Poetry appears to assume that pytype is also being installed for older Python versions such as 3.4, unsupported by pytype.Since the root package already requires Python
^3.6, Poetry should be able to work out that pytype cannot possibly be installed in an environment violating the Python version constraint.