Make sure tuple behaves similar to Tuple, fixes #2040

This commit is contained in:
Dave Halter
2026-04-30 00:15:56 +02:00
parent 4f7dfd14b3
commit a1d9da0a7f
2 changed files with 17 additions and 0 deletions
+4
View File
@@ -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)
+13
View File
@@ -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