Skip to content

Commit b9c1b90

Browse files
authored
Merge pull request #275 from avlonder/master
fix readonly __args__
2 parents ae4fd06 + e75407d commit b9c1b90

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

dacite/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from dacite.frozen_dict import FrozenDict
66

7-
if sys.version_info.minor >= 8:
7+
if sys.version_info >= (3, 8):
88
from functools import cached_property # type: ignore # pylint: disable=no-name-in-module
99
else:
1010
# Remove when we drop support for Python<3.8

dacite/generics.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ def __concretize(
5656
hint_origin = get_origin(hint)
5757
hint_args = get_args(hint)
5858
if hint_origin and hint_args and hint_origin is not Literal:
59-
concretized = tuple(__concretize(a, generics, data_class) for a in hint_args)
60-
if concretized != hint_args:
61-
try:
62-
hint.__args__ = concretized
63-
except AttributeError as err:
64-
raise DaciteError(f"Could not set __args__ on {hint} [original error: {err}]") from None
59+
concrete_hint_args = tuple(__concretize(a, generics, data_class) for a in hint_args)
60+
if concrete_hint_args != hint_args:
61+
if sys.version_info >= (3, 9):
62+
return hint_origin[concrete_hint_args]
63+
# It's generally not a good practice to overwrite __args__,
64+
# and it even has become impossible starting from python 3.13 (read-only),
65+
# but changing the output of get_type_hints is harmless (see unit test)
66+
# and at least this way, we get it working for python 3.8.
67+
hint.__args__ = concrete_hint_args
6568

6669
return hint
6770

0 commit comments

Comments
 (0)