Skip to content

PEP 695 not fully supported #611

Closed

Description

@rafales
  • 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.

Activity

  1. Tinche commented on Dec 12, 2024

    @Tinche
    Member

    Interesting, good catch!

  2. added this to the 24.2 milestone on Dec 12, 2024
  3. linked a pull request that will close this issuetype aliases: support generics #618on Jan 6, 2025
  4. Tinche commented on Jan 7, 2025

    @Tinche
    Member

    Think I got it!

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions