mirror of
https://github.com/davidhalter/jedi.git
synced 2026-01-30 21:15:23 +08:00
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)
|
||||
elif name == 'cast':
|
||||
# TODO implement cast
|
||||
for c in self._wrapped_name.infer(): # Fuck my life Python 2
|
||||
yield c
|
||||
yield CastFunction.create_cached(evaluator, self.parent_context, self.tree_name)
|
||||
elif name == 'TypedDict':
|
||||
# TODO doesn't even exist in typeshed/typing.py, yet. But will be
|
||||
# added soon.
|
||||
@@ -449,6 +448,12 @@ class OverloadFunction(_BaseTypingContext):
|
||||
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):
|
||||
"""
|
||||
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']
|
||||
#? int
|
||||
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