Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mypy error on structure #111

Open
gleb-chipiga opened this issue Jan 8, 2021 · 4 comments
Open

Mypy error on structure #111

gleb-chipiga opened this issue Jan 8, 2021 · 4 comments

Comments

@gleb-chipiga
Copy link

  • 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)
@gleb-chipiga gleb-chipiga changed the title Mypy error on ctructure Mypy error on structure Jan 8, 2021
@Tinche
Copy link
Member

Tinche commented Jan 22, 2021

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.

@Tinche
Copy link
Member

Tinche commented Jan 22, 2021

Note that I have to change this type annotation to Any, since there's no better way to type check this atm.

@Tinche
Copy link
Member

Tinche commented Jan 23, 2021

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.

@Tinche
Copy link
Member

Tinche commented Jan 23, 2021

We're waiting on this: python/mypy#9773

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants