Skip to content

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

@JimDabell

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)

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