2 This module is about generics, like the `int` in `List[int]`. It's not about
7 from jedi
.cache
import memoize_method
8 from jedi
.inference
.utils
import to_tuple
9 from jedi
.inference
.base_value
import ValueSet
, NO_VALUES
10 from jedi
.inference
.value
.iterable
import SequenceLiteralValue
11 from jedi
.inference
.helpers
import is_string
14 def _resolve_forward_references(context
, value_set
):
15 for value
in value_set
:
17 from jedi
.inference
.gradual
.annotation
import _get_forward_reference_node
18 node
= _get_forward_reference_node(context
, value
.get_safe_value())
20 for c
in context
.infer_node(node
):
26 class _AbstractGenericManager
:
27 def get_index_and_execute(self
, index
):
29 return self
[index
].execute_annotation()
31 debug
.warning('No param #%s found for annotation %s', index
, self
)
34 def get_type_hint(self
):
35 return '[%s]' % ', '.join(t
.get_type_hint(add_class_info
=False) for t
in self
.to_tuple())
38 class LazyGenericManager(_AbstractGenericManager
):
39 def __init__(self
, context_of_index
, index_value
):
40 self
._context
_of
_index
= context_of_index
41 self
._index
_value
= index_value
44 def __getitem__(self
, index
):
45 return self
._tuple
()[index
]()
48 return len(self
._tuple
())
53 def lambda_scoping_in_for_loop_sucks(lazy_value
):
54 return lambda: ValueSet(_resolve_forward_references(
55 self
._context
_of
_index
,
59 if isinstance(self
._index
_value
, SequenceLiteralValue
):
60 for lazy_value
in self
._index
_value
.py__iter__(contextualized_node
=None):
61 yield lambda_scoping_in_for_loop_sucks(lazy_value
)
63 yield lambda: ValueSet(_resolve_forward_references(
64 self
._context
_of
_index
,
65 ValueSet([self
._index
_value
])
70 for callable_
in self
._tuple
():
73 def is_homogenous_tuple(self
):
74 if isinstance(self
._index
_value
, SequenceLiteralValue
):
75 entries
= self
._index
_value
.get_tree_entries()
76 if len(entries
) == 2 and entries
[1] == '...':
81 return '<LazyG>[%s]' % (', '.join(repr(x
) for x
in self
.to_tuple()))
84 class TupleGenericManager(_AbstractGenericManager
):
85 def __init__(self
, tup
):
88 def __getitem__(self
, index
):
89 return self
._tuple
[index
]
92 return len(self
._tuple
)
97 def is_homogenous_tuple(self
):
101 return '<TupG>[%s]' % (', '.join(repr(x
) for x
in self
.to_tuple()))