cattrs icon indicating copy to clipboard operation
cattrs copied to clipboard

Tuple[A, B] can be structured from a list with less than two values

Open madig opened this issue 6 years ago • 1 comments

  • cattrs version: 0.9.0
  • Python version: 3.7.2
  • Operating System: Win 10 x64

Description

When structuring a list using the type Tuple[float, float], cattrs will happily construct a tuple from a list with less than two values. I was expecting an error instead. Is this intentional?

What I Did

In [17]: from typing import Tuple

In [18]: cattr.structure([1,2], Tuple[float, float])
Out[18]: (1.0, 2.0)

In [19]: cattr.structure([1], Tuple[float, float])
Out[19]: (1.0,)

In [20]: cattr.structure([], Tuple[float, float])
Out[20]: ()

madig avatar Feb 19 '19 12:02 madig

Not intentional. Will take a PR if it's simple to fix :)

Tinche avatar Feb 19 '19 14:02 Tinche