File: test_generics_649.py

package info (click to toggle)
python-cattrs 25.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,812 kB
  • sloc: python: 12,236; makefile: 155
file content (25 lines) | stat: -rw-r--r-- 603 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Tests for PEP 649 (Deferred Evaluation Of Annotations Using Descriptors)."""

from __future__ import annotations

from typing import Generic, TypeVar

from attrs import define

from cattrs import Converter

T = TypeVar("T")


@define
class GenericClass(Generic[T]):
    t: T


def test_generics_with_stringified_annotations():
    """Type resolution works with stringified annotations."""
    converter = Converter()
    inst = GenericClass(42)
    dct = converter.unstructure(inst, unstructure_as=GenericClass[int])
    assert dct == {"t": 42}
    assert converter.structure(dct, GenericClass[int])