Skip to content

Incorrect typing for register_structure_hook() and register_unstructure_hook() #581

Closed

Description

@JimDabell
  • cattrs version: 24.1.1
  • Python version: 3.12.6
  • Operating System: macOS Sequoia 15.0 (24A335)

Description

Custom (un)structuring hooks appear to have incorrect typing information. cattrs v24.1.1 already seems to have fixed this for the factory variant, as described in #578 and #579, but the individual hooks still seem to be incorrect.

What I Did

The following sample code is provided by the documentation :

@converter.register_structure_hook
def my_int_hook(val: Any, _) -> int:
    """This hook will be registered for `int`s."""
    return int(val)

This causes the following type warning (using Pylance in VS Code):

No overloads for "register_structure_hook" match the provided arguments
  Argument types: ((val: Any, _: Unknown) -> int)

Activity

  1. Tinche commented on Sep 16, 2024

    @Tinche
    Member

    Bleh, guess I need to do another pass on this.

    Wish there was a good way to test types; I've used the pytest-mypy-plugins package on a branch but wasn't super happy with it.

  2. Tinche commented on Sep 22, 2024

    @Tinche
    Member

    Alright, think I got this fixed. Thanks!

  3. JimDabell commented on Sep 27, 2024

    @JimDabell
    Author

    Just confirming that’s fixed for me. Thanks!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions