-
-
Notifications
You must be signed in to change notification settings - Fork 129
Closed as not planned
Closed as not planned
Copy link
Description
- cattrs version: 24.1.2
- Python version:
>>> import sys
>>> sys.version_info
sys.version_info(major=3, minor=11, micro=9, releaselevel='final', serial=0)- Operating System: macOS Ventura
Description
Structure raw data into an instance of a class, in such a way that container type is respected.
What I Did
>>> @define
... class C:
... a: int
... b: set[str]
...
>>> instance = structure({'a': 1, 'b': ['x', 'y']}, C)
>>> instance
C(a=1, b={'x', 'y'})What I Expect
I expect a failure, since the list[str] value for the b key doesn't conform to the set[str] type of the corresponding member of the class. This violates separation of concerns: the structure call is also deduplicating elements of the list, then, for the conversion to a set. As such, a reasonable invariant like "each collections in the raw data should have the same size as the corresponding collection once structured into the class" can be violated.
Metadata
Metadata
Assignees
Labels
No labels