diff --git a/src/cattrs/_compat.py b/src/cattrs/_compat.py index e7a87820..bc20b2dc 100644 --- a/src/cattrs/_compat.py +++ b/src/cattrs/_compat.py @@ -149,8 +149,11 @@ def fields_dict(type) -> dict[str, Union[Attribute, Field]]: return attrs_fields_dict(type) -def adapted_fields(cl) -> list[Attribute]: - """Return the attrs format of `fields()` for attrs and dataclasses.""" +def adapted_fields(cl: type) -> list[Attribute]: + """Return the attrs format of `fields()` for attrs and dataclasses. + + Resolves `attrs` stringified annotations, if present. + """ if is_dataclass(cl): attrs = dataclass_fields(cl) if any(isinstance(a.type, str) for a in attrs): diff --git a/src/cattrs/gen/__init__.py b/src/cattrs/gen/__init__.py index cfaddc9d..6fc2d77f 100644 --- a/src/cattrs/gen/__init__.py +++ b/src/cattrs/gen/__init__.py @@ -240,10 +240,6 @@ def make_dict_unstructure_fn( origin = get_origin(cl) attrs = adapted_fields(origin or cl) # type: ignore - if any(isinstance(a.type, str) for a in attrs): - # PEP 563 annotations - need to be resolved. - resolve_types(cl) - mapping = {} if is_generic(cl): mapping = generate_mapping(cl, mapping) @@ -743,10 +739,6 @@ def make_dict_structure_fn( attrs = adapted_fields(cl) - if any(isinstance(a.type, str) for a in attrs): - # PEP 563 annotations - need to be resolved. - resolve_types(cl) - # We keep track of what we're generating to help with recursive # class graphs. try: