mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-06 19:23:59 +08:00
Make sure tuple behaves similar to Tuple, fixes #2040
This commit is contained in:
@@ -145,6 +145,10 @@ class InferenceState:
|
||||
typing_module, = self.import_module(('types',))
|
||||
return typing_module
|
||||
|
||||
@inference_state_function_cache()
|
||||
def typing_tuple(self):
|
||||
return self.typing_module.py__getattribute__("Tuple")
|
||||
|
||||
def reset_recursion_limitations(self):
|
||||
self.recursion_detector = recursion.RecursionDetector()
|
||||
self.execution_recursion_detector = recursion.ExecutionRecursionDetector(self)
|
||||
|
||||
@@ -909,6 +909,15 @@ class EnumInstance(LazyValueWrapper):
|
||||
yield f
|
||||
|
||||
|
||||
# Make sure tuple[...] behaves like Tuple[...]
|
||||
class TupleClassWrapper(ValueWrapper):
|
||||
def py__getitem__(self, index_value_set, contextualized_node):
|
||||
return self.inference_state.typing_tuple().py__getitem__(
|
||||
index_value_set,
|
||||
contextualized_node,
|
||||
)
|
||||
|
||||
|
||||
def tree_name_to_values(func):
|
||||
def wrapper(inference_state, context, tree_name):
|
||||
if tree_name.value == 'sep' \
|
||||
@@ -916,5 +925,9 @@ def tree_name_to_values(func):
|
||||
return ValueSet({
|
||||
compiled.create_simple_object(inference_state, os.path.sep),
|
||||
})
|
||||
if tree_name.value == 'tuple' \
|
||||
and context.is_module() and context.py__name__() == 'builtins':
|
||||
tup, = func(inference_state, context, tree_name)
|
||||
return ValueSet([TupleClassWrapper(tup)])
|
||||
return func(inference_state, context, tree_name)
|
||||
return wrapper
|
||||
|
||||
Reference in New Issue
Block a user