Skip to content

Commit

Permalink
Evaluate ForwardRef before type params substiturion
Browse files Browse the repository at this point in the history
  • Loading branch information
Fatal1ty committed Nov 14, 2023
1 parent 7a1d012 commit e054a06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions mashumaro/core/meta/types/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def _pack_with_annotated_serialization_strategy(
)
except (KeyError, ValueError):
value_type = Any
if isinstance(value_type, ForwardRef):
value_type = spec.builder.evaluate_forward_ref(
value_type, spec.origin_type
)
value_type = substitute_type_params(
value_type,
resolve_type_params(strategy_type, get_args(spec.type))[strategy_type],
Expand Down Expand Up @@ -176,6 +180,10 @@ def _pack_annotated_serializable_type(
) from None
if is_self(value_type):
return f"{spec.expression}._serialize()"
if isinstance(value_type, ForwardRef):
value_type = spec.builder.evaluate_forward_ref(
value_type, spec.origin_type
)
value_type = substitute_type_params(
value_type,
resolve_type_params(spec.origin_type, get_args(spec.type))[
Expand Down
8 changes: 8 additions & 0 deletions mashumaro/core/meta/types/unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,10 @@ def _unpack_with_annotated_serialization_strategy(
)
except (KeyError, ValueError):
value_type = Any
if isinstance(value_type, ForwardRef):
value_type = spec.builder.evaluate_forward_ref(
value_type, spec.origin_type
)
value_type = substitute_type_params(
value_type,
resolve_type_params(strategy_type, get_args(spec.type))[strategy_type],
Expand Down Expand Up @@ -540,6 +544,10 @@ def _unpack_annotated_serializable_type(
) from None
if is_self(value_type):
return f"{type_name(spec.type)}._deserialize({spec.expression})"
if isinstance(value_type, ForwardRef):
value_type = spec.builder.evaluate_forward_ref(
value_type, spec.origin_type
)
value_type = substitute_type_params(
value_type,
resolve_type_params(spec.origin_type, get_args(spec.type))[
Expand Down

0 comments on commit e054a06

Please sign in to comment.