forked from VimPlug/jedi
Implement type[...]
This commit is contained in:
@@ -149,6 +149,10 @@ class InferenceState:
|
|||||||
def typing_tuple(self):
|
def typing_tuple(self):
|
||||||
return self.typing_module.py__getattribute__("Tuple")
|
return self.typing_module.py__getattribute__("Tuple")
|
||||||
|
|
||||||
|
@inference_state_function_cache()
|
||||||
|
def typing_type(self):
|
||||||
|
return self.typing_module.py__getattribute__("Type")
|
||||||
|
|
||||||
def reset_recursion_limitations(self):
|
def reset_recursion_limitations(self):
|
||||||
self.recursion_detector = recursion.RecursionDetector()
|
self.recursion_detector = recursion.RecursionDetector()
|
||||||
self.execution_recursion_detector = recursion.ExecutionRecursionDetector(self)
|
self.execution_recursion_detector = recursion.ExecutionRecursionDetector(self)
|
||||||
|
|||||||
@@ -285,7 +285,6 @@ class ClassMixin:
|
|||||||
if not is_instance and include_type_when_class:
|
if not is_instance and include_type_when_class:
|
||||||
from jedi.inference.compiled import builtin_from_name
|
from jedi.inference.compiled import builtin_from_name
|
||||||
type_ = builtin_from_name(self.inference_state, 'type')
|
type_ = builtin_from_name(self.inference_state, 'type')
|
||||||
assert isinstance(type_, ClassValue)
|
|
||||||
if type_ != self:
|
if type_ != self:
|
||||||
# We are not using execute_with_values here, because the
|
# We are not using execute_with_values here, because the
|
||||||
# plugin function for type would get executed instead of an
|
# plugin function for type would get executed instead of an
|
||||||
|
|||||||
@@ -918,6 +918,15 @@ class TupleClassWrapper(ValueWrapper):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Make sure type[...] behaves like Type[...]
|
||||||
|
class TypeClassWrapper(ValueWrapper):
|
||||||
|
def py__getitem__(self, index_value_set, contextualized_node):
|
||||||
|
return self.inference_state.typing_type().py__getitem__(
|
||||||
|
index_value_set,
|
||||||
|
contextualized_node,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def tree_name_to_values(func):
|
def tree_name_to_values(func):
|
||||||
def wrapper(inference_state, context, tree_name):
|
def wrapper(inference_state, context, tree_name):
|
||||||
if tree_name.value == 'sep' \
|
if tree_name.value == 'sep' \
|
||||||
@@ -929,5 +938,9 @@ def tree_name_to_values(func):
|
|||||||
and context.is_module() and context.py__name__() == 'builtins':
|
and context.is_module() and context.py__name__() == 'builtins':
|
||||||
tup, = func(inference_state, context, tree_name)
|
tup, = func(inference_state, context, tree_name)
|
||||||
return ValueSet([TupleClassWrapper(tup)])
|
return ValueSet([TupleClassWrapper(tup)])
|
||||||
|
if tree_name.value == 'type' \
|
||||||
|
and context.is_module() and context.py__name__() == 'builtins':
|
||||||
|
tup, = func(inference_state, context, tree_name)
|
||||||
|
return ValueSet([TypeClassWrapper(tup)])
|
||||||
return func(inference_state, context, tree_name)
|
return func(inference_state, context, tree_name)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|||||||
@@ -225,3 +225,8 @@ def check_newstyle_unions(u1: int | str, u2: list[int] | list[str]):
|
|||||||
u2
|
u2
|
||||||
#? int() str()
|
#? int() str()
|
||||||
u2[1]
|
u2[1]
|
||||||
|
|
||||||
|
def use_type_with_annotation() -> type[int]: ...
|
||||||
|
|
||||||
|
#? int
|
||||||
|
use_type_with_annotation()
|
||||||
|
|||||||
Reference in New Issue
Block a user