Skip to content

Bug with tracebacks on IPython when detailed_validations=True #590

Closed as not planned
@edthrn

Description

@edthrn
  • cattrs version: 24.1.2
  • Python version: 3.11
  • Operating System: Linux

Description

import attrs, cattrs

@attrs.define
class Test:
    a: int
    b: str

cattrs.structure({"a": "hello", "b": "world"}, Test)

The expected traceback is the following:

  + Exception Group Traceback (most recent call last):
  |   File "/tmp/test_cattrs.py", line 8, in <module>
  |     cattrs.structure({"a": "hello", "b": "world"}, Test)
  |   File "<redacted>/lib/python3.11/site-packages/cattrs/converters.py", line 558, in structure
  |     return self._structure_func.dispatch(cl)(obj, cl)
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |   File "<cattrs generated structure __main__.Test>", line 14, in structure_Test
  | cattrs.errors.ClassValidationError: While structuring Test (1 sub-exception)
  +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    |   File "<cattrs generated structure __main__.Test>", line 5, in structure_Test
    | ValueError: invalid literal for int() with base 10: 'hello'
    | Structuring class Test @ attribute a
    +------------------------------------

⚠️ HOWEVER, if you execute this Python code within IPython or a Jupyter Notebook, the helpful traceback is lost, and we get another error that don't relate to the actual validation problem:

image
The following code is expected to raise an error:

Edit

When turning off detailed_validation, the error message is the expected one:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions