mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-08 06:44:46 +08:00
Start implementing overload function
This commit is contained in:
@@ -92,7 +92,7 @@ def _execute(context, arguments):
|
|||||||
debug.warning("no execution possible %s", context)
|
debug.warning("no execution possible %s", context)
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
else:
|
else:
|
||||||
context_set = func(arguments)
|
context_set = func(arguments=arguments)
|
||||||
debug.dbg('execute result: %s in %s', context_set, context)
|
debug.dbg('execute result: %s in %s', context_set, context)
|
||||||
return context_set
|
return context_set
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from parso.python import tree
|
|||||||
|
|
||||||
from jedi._compatibility import zip_longest
|
from jedi._compatibility import zip_longest
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
|
from jedi.evaluate.utils import to_list
|
||||||
from jedi.evaluate import analysis
|
from jedi.evaluate import analysis
|
||||||
from jedi.evaluate.lazy_context import LazyKnownContext, LazyKnownContexts, \
|
from jedi.evaluate.lazy_context import LazyKnownContext, LazyKnownContexts, \
|
||||||
LazyTreeContext, get_merged_lazy_context
|
LazyTreeContext, get_merged_lazy_context
|
||||||
|
|||||||
@@ -54,19 +54,21 @@ class CompiledObject(Context):
|
|||||||
self.tree_node = faked_class
|
self.tree_node = faked_class
|
||||||
|
|
||||||
@CheckAttribute()
|
@CheckAttribute()
|
||||||
def py__call__(self, params):
|
def py__call__(self, arguments):
|
||||||
if self.tree_node is not None and self.tree_node.type == 'funcdef':
|
if self.tree_node is not None and self.tree_node.type == 'funcdef':
|
||||||
from jedi.evaluate.context.function import FunctionContext
|
from jedi.evaluate.context.function import FunctionContext
|
||||||
return FunctionContext(
|
return FunctionContext(
|
||||||
self.evaluator,
|
self.evaluator,
|
||||||
parent_context=self.parent_context,
|
parent_context=self.parent_context,
|
||||||
tree_node=self.tree_node
|
tree_node=self.tree_node
|
||||||
).py__call__(params)
|
).py__call__(arguments=arguments)
|
||||||
if self.access_handle.is_class():
|
if self.access_handle.is_class():
|
||||||
from jedi.evaluate.context import CompiledInstance
|
from jedi.evaluate.context import CompiledInstance
|
||||||
return ContextSet(CompiledInstance(self.evaluator, self.parent_context, self, params))
|
return ContextSet(
|
||||||
|
CompiledInstance(self.evaluator, self.parent_context, self, arguments)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
return ContextSet.from_iterable(self._execute_function(params))
|
return ContextSet.from_iterable(self._execute_function(arguments))
|
||||||
|
|
||||||
@CheckAttribute()
|
@CheckAttribute()
|
||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class AbstractInstanceContext(Context):
|
|||||||
def py__getitem__(self, index_context_set, contextualized_node):
|
def py__getitem__(self, index_context_set, contextualized_node):
|
||||||
names = self.get_function_slot_names(u'__getitem__')
|
names = self.get_function_slot_names(u'__getitem__')
|
||||||
if not names:
|
if not names:
|
||||||
debug.warning('No __getitem__, cannot access the array.')
|
debug.warning('Found no __getitem__ on %s', self)
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|
||||||
args = ValuesArguments([index_context_set])
|
args = ValuesArguments([index_context_set])
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ and others. Here's a list:
|
|||||||
====================================== ========================================
|
====================================== ========================================
|
||||||
**Method** **Description**
|
**Method** **Description**
|
||||||
-------------------------------------- ----------------------------------------
|
-------------------------------------- ----------------------------------------
|
||||||
py__call__(params: Array) On callable objects, returns types.
|
py__call__(arguments: Array) On callable objects, returns types.
|
||||||
py__bool__() Returns True/False/None; None means that
|
py__bool__() Returns True/False/None; None means that
|
||||||
there's no certainty.
|
there's no certainty.
|
||||||
py__bases__() Returns a list of base classes.
|
py__bases__() Returns a list of base classes.
|
||||||
@@ -168,9 +168,9 @@ class ClassContext(use_metaclass(CachedMetaClass, TreeContext)):
|
|||||||
else:
|
else:
|
||||||
return [LazyKnownContext(compiled.builtin_from_name(self.evaluator, u'object'))]
|
return [LazyKnownContext(compiled.builtin_from_name(self.evaluator, u'object'))]
|
||||||
|
|
||||||
def py__call__(self, params):
|
def py__call__(self, arguments):
|
||||||
from jedi.evaluate.context import TreeInstance
|
from jedi.evaluate.context import TreeInstance
|
||||||
return ContextSet(TreeInstance(self.evaluator, self.parent_context, self, params))
|
return ContextSet(TreeInstance(self.evaluator, self.parent_context, self, arguments))
|
||||||
|
|
||||||
def py__class__(self):
|
def py__class__(self):
|
||||||
return compiled.builtin_from_name(self.evaluator, u'type')
|
return compiled.builtin_from_name(self.evaluator, u'type')
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from jedi import debug
|
|||||||
from jedi.evaluate.compiled import builtin_from_name, CompiledObject
|
from jedi.evaluate.compiled import builtin_from_name, CompiledObject
|
||||||
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, Context
|
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, Context
|
||||||
from jedi.evaluate.context.iterable import SequenceLiteralContext
|
from jedi.evaluate.context.iterable import SequenceLiteralContext
|
||||||
|
from jedi.evaluate.arguments import repack_with_argument_clinic
|
||||||
from jedi.evaluate.filters import FilterWrapper, NameWrapper, \
|
from jedi.evaluate.filters import FilterWrapper, NameWrapper, \
|
||||||
AbstractTreeName
|
AbstractTreeName
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ class TypingModuleName(NameWrapper):
|
|||||||
evaluator = self.parent_context.evaluator
|
evaluator = self.parent_context.evaluator
|
||||||
if name in (_PROXY_CLASS_TYPES + _TYPE_ALIAS_TYPES):
|
if name in (_PROXY_CLASS_TYPES + _TYPE_ALIAS_TYPES):
|
||||||
yield TypingClassContext(self)
|
yield TypingClassContext(self)
|
||||||
elif name == _PROXY_TYPES:
|
elif name in _PROXY_TYPES:
|
||||||
yield TypingContext(self)
|
yield TypingContext(self)
|
||||||
elif name == 'runtime':
|
elif name == 'runtime':
|
||||||
# We don't want anything here, not sure what this function is
|
# We don't want anything here, not sure what this function is
|
||||||
@@ -75,7 +76,7 @@ class TypingModuleName(NameWrapper):
|
|||||||
yield builtin_from_name(evaluator, u'True')
|
yield builtin_from_name(evaluator, u'True')
|
||||||
elif name == 'overload':
|
elif name == 'overload':
|
||||||
# TODO implement overload
|
# TODO implement overload
|
||||||
pass
|
yield OverloadFunction(self)
|
||||||
elif name == 'cast':
|
elif name == 'cast':
|
||||||
# TODO implement cast
|
# TODO implement cast
|
||||||
for c in self._wrapped_name.infer(): # Fuck my life Python 2
|
for c in self._wrapped_name.infer(): # Fuck my life Python 2
|
||||||
@@ -305,3 +306,10 @@ class TypeVar(Context):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (self.__class__.__name__, self._name)
|
return '<%s: %s>' % (self.__class__.__name__, self._name)
|
||||||
|
|
||||||
|
|
||||||
|
class OverloadFunction(_BaseTypingContext):
|
||||||
|
@repack_with_argument_clinic('func, /')
|
||||||
|
def py__call__(self, func_context_set):
|
||||||
|
debug.warning('overload used')
|
||||||
|
return NO_CONTEXTS
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ class StdlibPlugin(BasePlugin):
|
|||||||
def execute(self, callback):
|
def execute(self, callback):
|
||||||
def wrapper(context, arguments):
|
def wrapper(context, arguments):
|
||||||
if isinstance(context, BoundMethod):
|
if isinstance(context, BoundMethod):
|
||||||
return callback(context, arguments)
|
return callback(context, arguments=arguments)
|
||||||
|
|
||||||
debug.dbg('execute: %s %s', context, arguments)
|
debug.dbg('execute: %s %s', context, arguments)
|
||||||
try:
|
try:
|
||||||
@@ -69,8 +69,8 @@ class StdlibPlugin(BasePlugin):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return func(self._evaluator, context, arguments)
|
return func(self._evaluator, context, arguments=arguments)
|
||||||
return callback(context, arguments)
|
return callback(context, arguments=arguments)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|||||||
@@ -311,7 +311,8 @@ class StubModuleContext(_StubContextFilterMixin, ModuleContext):
|
|||||||
|
|
||||||
class StubClassContext(_StubContextFilterMixin, ClassContext):
|
class StubClassContext(_StubContextFilterMixin, ClassContext):
|
||||||
def __getattribute__(self, name):
|
def __getattribute__(self, name):
|
||||||
if name == ('py__getitem__', 'py__simple_getitem__', 'py__bases__'):
|
if name in ('py__getitem__', 'py__simple_getitem__', 'py__bases__',
|
||||||
|
'execute_annotation'):
|
||||||
# getitem is always done in the stub class.
|
# getitem is always done in the stub class.
|
||||||
return getattr(self.stub_context, name)
|
return getattr(self.stub_context, name)
|
||||||
return super(StubClassContext, self).__getattribute__(name)
|
return super(StubClassContext, self).__getattribute__(name)
|
||||||
|
|||||||
Reference in New Issue
Block a user