cattrs icon indicating copy to clipboard operation
cattrs copied to clipboard

ModuleNotFoundError: No module named 'exceptiongroup' (with poetry and python 3.10.1+)

Open JWCook opened this issue 3 years ago • 5 comments

Environment

  • cattrs version: 22.1.0
  • Python version: 3.10.5
  • Operating System: Ubuntu 22.04

Description

When using poetry, the dependency spec for cattrs 22.1.0 doesn't install exceptiongroup for python versions >=3.10.1, <3.11.

It seems that pip interprets the constraint python = "<= 3.10" as roughly equivalent to python = "< 3.11", whereas poetry interprets it (perhaps more correctly?) as python = "<= 3.10.0", so doesn't behave correctly for patch versions greater than 0. In other words, on python 3.10.1, poetry's dependency resolver thinks exceptiongroup doesn't need to be installed.

Looks like this was already fixed in main. No need to rush the next minor release (22.2.0) if it's not ready, but a patch release for this (22.1.1) would be helpful.

What I Did

Start with python 3.10.1+ installed, and a minimal pyproject.toml:

[tool.poetry]
name = "cattrs-test"
version = "0.1.0"
description = ""
authors = []

[tool.poetry.dependencies]
python = ">=3.10.1,<3.11"
cattrs = "22.1.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Then run from the command line:

pip install poetry  # If not already installed
poetry install
python -c "import cattrs"

Traceback:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/user/.virtualenvs/cattrs-test/lib/python3.10/site-packages/cattrs/__init__.py", line 1, in <module>
    from cattr import converters, disambiguators, dispatch, errors, gen, preconf
  File "/home/user/.virtualenvs/cattrs-test/lib/python3.10/site-packages/cattr/__init__.py", line 1, in <module>
    from .converters import Converter, GenConverter, UnstructureStrategy
  File "/home/user/.virtualenvs/cattrs-test/lib/python3.10/site-packages/cattr/converters.py", line 1, in <module>
    from cattrs.converters import Converter, GenConverter, UnstructureStrategy
  File "/home/user/.virtualenvs/cattrs-test/lib/python3.10/site-packages/cattrs/converters.py", line 12, in <module>
    from cattrs.errors import IterableValidationError, StructureHandlerNotFoundError
  File "/home/user/.virtualenvs/cattrs-test/lib/python3.10/site-packages/cattrs/errors.py", line 3, in <module>
    from cattrs._compat import ExceptionGroup
  File "/home/user/.virtualenvs/cattrs-test/lib/python3.10/site-packages/cattrs/_compat.py", line 38, in <module>
    from exceptiongroup import ExceptionGroup
ModuleNotFoundError: No module named 'exceptiongroup'

Attached is an example poetry.lock showing that exceptiongroup wasn't picked up by the dependency resolver.

Workaround

This can be worked around by adding an explicit dependency on exceptiongroup, so I wouldn't consider this a super serious bug, but it would be helpful to have a PyPI release that fixes this for other users of cattrs + poetry + python 3.10.

JWCook avatar Jun 29 '22 17:06 JWCook

Oh interesting, we've seen this at my job too but figured it was some sort of Poetry weirdness.

What's the exact fix though? Make it < 3.11?

Tinche avatar Jun 29 '22 21:06 Tinche

That's right, the change you already made here: https://github.com/python-attrs/cattrs/blob/b1a681a60d07623618dfe440ac9c3ee6b9780307/pyproject.toml#L27

Works correctly for both pip and poetry.

JWCook avatar Jun 29 '22 22:06 JWCook

Cool. Guess I need to get a move on on finishing up the next version :p

Tinche avatar Jun 29 '22 22:06 Tinche

Thanks!

Tinche avatar Jun 29 '22 22:06 Tinche

Sure! And thank you for the lovely library.

JWCook avatar Jun 29 '22 22:06 JWCook

This is now fixed with the 22.2 release. Thanks!

JWCook avatar Oct 08 '22 19:10 JWCook