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

PEP 695 not fully supported #611

Closed
rafales opened this issue Dec 12, 2024 · 2 comments · Fixed by #618
Closed

PEP 695 not fully supported #611

rafales opened this issue Dec 12, 2024 · 2 comments · Fixed by #618
Milestone

Comments

@rafales
Copy link

rafales commented Dec 12, 2024

  • cattrs version: 24.1.2
  • Python version: 3.12.7

Description

So I've seen #452 and that "type" alises should work, but I think generic ones are missing.

What I Did

In [2]: import cattrs

In [3]: type Lol = int

In [4]: c = cattrs.Converter()

In [5]: c.structure(1, Lol)
Out[5]: 1

In [6]: type Indexed[T] = T

In [7]: c.structure(1, Indexed[int])
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:1                                                                                    │
│                                                                                                  │
│ /Users/rafal/Code/censored/.venv/lib/python3.12/site-packages/cattrs/converters.py:558 in   │
│ structure                                                                                        │
│                                                                                                  │
│    555 │                                                                                         │
│    556 │   def structure(self, obj: UnstructuredValue, cl: type[T]) -> T:                        │
│    557 │   │   """Convert unstructured Python data structures to structured data."""             │
│ ❱  558 │   │   return self._structure_func.dispatch(cl)(obj, cl)                                 │
│    559 │                                                                                         │
│    560 │   def get_structure_hook(self, type: Any, cache_result: bool = True) -> StructureHook:  │
│    561 │   │   """Get the structure hook for the given type.                                     │
│                                                                                                  │
│ /Users/rafal/Code/censored/.venv/lib/python3.12/site-packages/cattrs/fns.py:22 in           │
│ raise_error                                                                                      │
│                                                                                                  │
│   19 def raise_error(_, cl: Type) -> NoReturn:                                                   │
│   20 │   """At the bottom of the condition stack, we explode if we can't handle it."""           │
│   21 │   msg = f"Unsupported type: {cl!r}. Register a structure hook for it."                    │
│ ❱ 22 │   raise StructureHandlerNotFoundError(msg, type_=cl)                                      │
│   23                                                                                             │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
StructureHandlerNotFoundError: Unsupported type: Indexed[int]. Register a structure hook for it.
@Tinche
Copy link
Member

Tinche commented Dec 12, 2024

Interesting, good catch!

@Tinche Tinche added this to the 24.2 milestone Dec 12, 2024
@Tinche Tinche linked a pull request Jan 6, 2025 that will close this issue
@Tinche
Copy link
Member

Tinche commented Jan 7, 2025

Think I got it!

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

Successfully merging a pull request may close this issue.

2 participants