cattrs
cattrs copied to clipboard
Mypy error on structure
- cattrs version: 1.1.2
- Python version: 3.8.6
- Operating System: Linux x86-64
Description
Run mypy on first example from readme and get error.
What I Did
import cattr
from typing import Tuple
cattr.structure([1.0, 2, "3"], Tuple[int, int, int])
$ mypy example.py
example.py:4: error: Argument 2 has incompatible type "object"; expected "Type[<nothing>]"
Found 1 error in 1 file (checked 1 source file)
Ah, I need to tweak the type annotation (turns out Type[C]
basically only works for classes, not abstract types like Tuple
or Optional
). Will do in the next couple of days.
Note that I have to change this type annotation to Any
, since there's no better way to type check this atm.
I actually needed to add some overloads. There's no way to correctly check cattr.structure([1.0, 2, "3"], Tuple[int, int, int])
with current Mypy as far as I'm aware. So in those cases you will have to suppress the error in any case.
We're waiting on this: https://github.com/python/mypy/issues/9773