Skip to content

GenConverter unstructures tuple to list if in union type.  #214

@aha79

Description

@aha79
  • cattrs version: 1.10
  • Python version: 3.9.7
  • Operating System: Windows 10

Description

GenConverter incorrectly unstructures tuples when in union (or optional). Converter does do it correctly.

Example:

from typing import Optional, Tuple
import cattr

orig = (1,'2')

c = cattr.Converter()
print( c.unstructure(orig, Tuple[int,str] ) )
# -> (1, '2')
print( c.unstructure(orig, Optional[Tuple[int,str]] ) )
# -> (1, '2')

c = cattr.GenConverter()
print( c.unstructure(orig, Tuple[int,str] ) )
# -> (1, '2')
print( c.unstructure(orig, Optional[Tuple[int,str]] ) )
# -> [1, '2']    <<< incorrect, no more tuple

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions