-
-
Notifications
You must be signed in to change notification settings - Fork 133
Description
- cattrs version:
22.1.0 - Python version:
3.9.11 - Operating System: Ubuntu
20.04.4LTS
Description
Using detailed_validation=False with a GenConverter breaks my application after upgrading to cattrs 22.1.0, but everything works swimingly with detailed_validation=True.
What I Did
Changed from:
CONVERTER = cattrs.GenConverter()
to:
CONVERTER = cattrs.GenConverter(detailed_validation=False)
At the moment, I don't have time to get a minimum reproducible example put together, and I can't share my code or full stack traces.
However, I can shore portions of it. It seems that the error occurs in the generated code that cattrs creates for my GenConverter instance. Specifically, it looks like the method signature for instantiating my attrs classes is different under detailed_validation=True vs. False, but I'm not 100% sure.
Here's where the error occurs in cattrs:
def _structure_list(self, obj, cl):
"""Convert an iterable to a potentially generic list."""
if is_bare(cl) or cl.__args__[0] is Any:
res = [e for e in obj]
else:
elem_type = cl.__args__[0]
handler = self._structure_func.dispatch(elem_type)
if self.detailed_validation:
errors = []
res = []
ix = 0 # Avoid `enumerate` for performance.
for e in obj:
try:
res.append(handler(e, elem_type))
except Exception as e:
e.__note__ = f"Structuring {cl} @ index {ix}"
errors.append(e)
finally:
ix += 1
if errors:
raise IterableValidationError(
f"While structuring {cl!r}", errors, cl
)
else:
> res = [handler(e, elem_type) for e in obj]
../path/to/my/environment/lib/python3.9/site-packages/cattrs/converters.py:474:
The error message seems to relate to bad arguments to the class signature:
E TypeError: __init__() takes 1 positional argument but 5 positional arguments (and 8 keyword-only arguments) were given
<cattrs generated structure REDACTED>:19: TypeError
If I find time, I'll try to get a minimal example together that I can share, but don't hold your breath :)