Skip to content

Mypy error on structure #111

Closed
Closed

Description

@gleb-chipiga
  • 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)

Activity

  1. changed the title [-]Mypy error on ctructure[/-] [+]Mypy error on structure[/+] on Jan 8, 2021
  2. Tinche commented on Jan 22, 2021

    @Tinche
    Member

    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.

  3. Tinche commented on Jan 22, 2021

    @Tinche
    Member

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

  4. Tinche commented on Jan 23, 2021

    @Tinche
    Member

    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.

  5. Tinche commented on Jan 23, 2021

    @Tinche
    Member

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

  6. AdrianSosic commented on Mar 4, 2026

    @AdrianSosic
    Contributor

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

    Is completed since end of last year. Does it auto-solve this issue?

  7. Tinche commented on Mar 4, 2026

    @Tinche
    Member

    The PEP was formally accepted 13 days ago. In Mypy it's still behind a feature flag, so not many will have it enabled by default.

    And it won't work by default, we'll need to change our type hints to use TypeForm[T] instead of type[T] in places. I've started on this in a branch but I don't think I want to merge it until Mypy supports it by default.

  8. layday commented on Sep 26, 2026

    @layday
    Contributor

    It'd be nice to get this in. Support for TypeForm landed in mypy 1.19 and has been enabled by default since 1.21.

  9. Tinche commented on Sep 27, 2026

    @Tinche
    Member

    Yeah, it's probably time. Started preliminary work over at #786.

  10. linked a pull request that will close this issueSwitch to TypeForm #786on Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions