Skip to content

A dictionary gets structured into a list without errors/warnings #504

Closed
@fjarri

Description

@fjarri
  • cattrs version: 23.2.0
  • Python version: 3.10
  • Operating System: macos 13.5.1

Description

>>> cattrs.structure({"a": 1, "b": 2}, List)
['a', 'b']

I would expect it to complain that the dictionary it's trying to structure is not a list. While I understand where this logic may be coming from (a dictionary is an Iterable, so it's fine to convert it to a list), it is losing information this way, which doesn't seem like a good choice for the default behavior. Also the docs don't list Iterable as something that gets structured to a list, and dictionaries are not Sequence.

Is it intentional, and if yes, is there a way to make it more strict, in a way that's composable (that is, so I don't have to define a custom structuring function for list of every type I have)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions