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

Final Types are not Recognized #340

Closed
dtoniolo opened this issue Mar 15, 2023 · 4 comments
Closed

Final Types are not Recognized #340

dtoniolo opened this issue Mar 15, 2023 · 4 comments
Milestone

Comments

@dtoniolo
Copy link

  • cattrs version: 22.2.0
  • Python version: 3.10.9
  • Operating System: Linux

Description

Hi, first of all thanks for the amazing work, I've recently begun using both attrs and cattrs and I find them very useful and elegant.

I'm trying to structure some custom classes and all of my type annotations are recognized correctly, except for those using typing.Final.

What I Did

Here's a minmum example to reproduce the issue:

from typing import Final
from attrs import frozen
import cattrs

@frozen
class Foo:
    a: Final[float]

cattrs.structure({"a": 1}, Foo)

Running this code results in a ClassValidationError with one sub-exception: a StructureHandlerNotFoundError which says "Unsupported type: Final[float]. Register a structure hook for it.".

Pitch

Final is one of the most basic type annotations in Python. Although I'm not familiar at all with cattrs internals, it shouldn't be too hard to add support for this type hint, as Final attributes should be structured and unstructured in the same way as their non-Finalcounterparts.

A Note About Frozen

attrs provides a frozen attribute (and I'm using that), but it's not the same thing. frozen operates at runtime, while Final can also be used during static analysis.

@dtoniolo dtoniolo changed the title Final Primitive Types are not Recognized Final Types are not Recognized Mar 15, 2023
@Tinche
Copy link
Member

Tinche commented Mar 15, 2023

You're right, we should support this. Let me see if I can get it into the next release.

@Tinche Tinche added this to the 22.3 milestone Mar 15, 2023
@dtoniolo
Copy link
Author

Awesome, thank you!

@Tinche
Copy link
Member

Tinche commented Apr 8, 2023

Fixed on main!

@Tinche Tinche closed this as completed Apr 8, 2023
@dtoniolo
Copy link
Author

Awesome, thank you!

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

No branches or pull requests

2 participants