Total Complexity | 9 |
Total Lines | 38 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import sys |
||
2 | import typing |
||
3 | |||
4 | from . import _ctor |
||
5 | from . import _nillable_write |
||
6 | |||
7 | _T = typing.TypeVar("_T") |
||
8 | |||
9 | |||
10 | def _all_annotations( |
||
11 | cls: typing.Type[_T] |
||
12 | ) -> typing.Iterator[typing.Tuple[typing.Type[_T], str, typing.Any]]: |
||
13 | for superclass in reversed(cls.__mro__): |
||
14 | for key, value in vars(superclass).get("__annotations__", {}).items(): |
||
15 | yield (superclass, key, value) |
||
16 | |||
17 | |||
18 | def _sum_args_from_annotations(cls: typing.Type[_T]) -> typing.Dict[str, typing.Tuple]: |
||
19 | args: typing.Dict[str, typing.Tuple] = {} |
||
20 | for superclass, key, value in _all_annotations(cls): |
||
21 | _nillable_write.nillable_write( |
||
22 | args, key, _ctor.get_args(value, vars(sys.modules[superclass.__module__])) |
||
23 | ) |
||
24 | return args |
||
25 | |||
26 | |||
27 | def _product_args_from_annotations( |
||
28 | cls: typing.Type[_T] |
||
29 | ) -> typing.Dict[str, typing.Any]: |
||
30 | args: typing.Dict[str, typing.Any] = {} |
||
31 | for superclass, key, value in _all_annotations(cls): |
||
32 | if value == "None" or _ctor.annotation_is_classvar( |
||
33 | value, vars(sys.modules[superclass.__module__]) |
||
34 | ): |
||
35 | value = None |
||
36 | _nillable_write.nillable_write(args, key, value) |
||
37 | return args |
||
38 |