forked from VimPlug/jedi
Implement typing.cast
This commit is contained in:
@@ -114,8 +114,7 @@ class TypingModuleName(NameWrapper):
|
|||||||
yield OverloadFunction.create_cached(evaluator, self.parent_context, self.tree_name)
|
yield OverloadFunction.create_cached(evaluator, self.parent_context, self.tree_name)
|
||||||
elif name == 'cast':
|
elif name == 'cast':
|
||||||
# TODO implement cast
|
# TODO implement cast
|
||||||
for c in self._wrapped_name.infer(): # Fuck my life Python 2
|
yield CastFunction.create_cached(evaluator, self.parent_context, self.tree_name)
|
||||||
yield c
|
|
||||||
elif name == 'TypedDict':
|
elif name == 'TypedDict':
|
||||||
# TODO doesn't even exist in typeshed/typing.py, yet. But will be
|
# TODO doesn't even exist in typeshed/typing.py, yet. But will be
|
||||||
# added soon.
|
# added soon.
|
||||||
@@ -449,6 +448,12 @@ class OverloadFunction(_BaseTypingContext):
|
|||||||
return func_context_set
|
return func_context_set
|
||||||
|
|
||||||
|
|
||||||
|
class CastFunction(_BaseTypingContext):
|
||||||
|
@repack_with_argument_clinic('type, object, /')
|
||||||
|
def py__call__(self, type_context_set, object_context_set):
|
||||||
|
return type_context_set.execute_annotation()
|
||||||
|
|
||||||
|
|
||||||
class BoundTypeVarName(AbstractNameDefinition):
|
class BoundTypeVarName(AbstractNameDefinition):
|
||||||
"""
|
"""
|
||||||
This type var was bound to a certain type, e.g. int.
|
This type var was bound to a certain type, e.g. int.
|
||||||
|
|||||||
@@ -351,3 +351,14 @@ def foo(a: typing.List, b: typing.Dict, c: typing.MutableMapping) -> typing.Type
|
|||||||
c['asdf']
|
c['asdf']
|
||||||
#? int
|
#? int
|
||||||
foo()
|
foo()
|
||||||
|
|
||||||
|
def cast_tests():
|
||||||
|
x = 3.0
|
||||||
|
y = typing.cast(int, x)
|
||||||
|
#? int()
|
||||||
|
y
|
||||||
|
return typing.cast(str, x)
|
||||||
|
|
||||||
|
|
||||||
|
#? str()
|
||||||
|
cast_tests()
|
||||||
|
|||||||
Reference in New Issue
Block a user