Skip to content

Commit

Permalink
Merge pull request #275 from avlonder/master
Browse files Browse the repository at this point in the history
fix readonly __args__
  • Loading branch information
mciszczon authored Feb 5, 2025
2 parents ae4fd06 + e75407d commit b9c1b90
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dacite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dacite.frozen_dict import FrozenDict

if sys.version_info.minor >= 8:
if sys.version_info >= (3, 8):
from functools import cached_property # type: ignore # pylint: disable=no-name-in-module
else:
# Remove when we drop support for Python<3.8
Expand Down
15 changes: 9 additions & 6 deletions dacite/generics.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,15 @@ def __concretize(
hint_origin = get_origin(hint)
hint_args = get_args(hint)
if hint_origin and hint_args and hint_origin is not Literal:
concretized = tuple(__concretize(a, generics, data_class) for a in hint_args)
if concretized != hint_args:
try:
hint.__args__ = concretized
except AttributeError as err:
raise DaciteError(f"Could not set __args__ on {hint} [original error: {err}]") from None
concrete_hint_args = tuple(__concretize(a, generics, data_class) for a in hint_args)
if concrete_hint_args != hint_args:
if sys.version_info >= (3, 9):
return hint_origin[concrete_hint_args]
# It's generally not a good practice to overwrite __args__,
# and it even has become impossible starting from python 3.13 (read-only),
# but changing the output of get_type_hints is harmless (see unit test)
# and at least this way, we get it working for python 3.8.
hint.__args__ = concrete_hint_args

return hint

Expand Down

0 comments on commit b9c1b90

Please sign in to comment.