File tree 2 files changed +10
-7
lines changed
2 files changed +10
-7
lines changed Original file line number Diff line number Diff line change 4
4
5
5
from dacite .frozen_dict import FrozenDict
6
6
7
- if sys .version_info . minor >= 8 :
7
+ if sys .version_info >= ( 3 , 8 ) :
8
8
from functools import cached_property # type: ignore # pylint: disable=no-name-in-module
9
9
else :
10
10
# Remove when we drop support for Python<3.8
Original file line number Diff line number Diff line change @@ -56,12 +56,15 @@ def __concretize(
56
56
hint_origin = get_origin (hint )
57
57
hint_args = get_args (hint )
58
58
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
65
68
66
69
return hint
67
70
You can’t perform that action at this time.
0 commit comments