Skip to content
New issue

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

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

Already on GitHub? # to your account

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

Closed
JimDabell opened this issue Sep 16, 2024 · 3 comments · Fixed by #582
Closed

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

JimDabell opened this issue Sep 16, 2024 · 3 comments · Fixed by #582

Comments

@JimDabell
Copy link

  • 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)
@Tinche
Copy link
Member

Tinche commented Sep 16, 2024

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.

@Tinche Tinche linked a pull request Sep 22, 2024 that will close this issue
@Tinche
Copy link
Member

Tinche commented Sep 22, 2024

Alright, think I got this fixed. Thanks!

@Tinche Tinche closed this as completed Sep 22, 2024
@JimDabell
Copy link
Author

Just confirming that’s fixed for me. Thanks!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants