mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 22:44:27 +08:00
Get some first stubs working
This commit is contained in:
@@ -33,26 +33,14 @@ class Context(BaseContext):
|
|||||||
# overwritten.
|
# overwritten.
|
||||||
return self.__class__.__name__.lower()
|
return self.__class__.__name__.lower()
|
||||||
|
|
||||||
@debug.increase_indent
|
|
||||||
def execute(self, arguments):
|
|
||||||
"""
|
|
||||||
In contrast to py__call__ this function is always available.
|
|
||||||
|
|
||||||
`hasattr(x, py__call__)` can also be checked to see if a context is
|
|
||||||
executable.
|
|
||||||
"""
|
|
||||||
if self.evaluator.is_analysis:
|
|
||||||
arguments.eval_all()
|
|
||||||
|
|
||||||
return self.evaluator.execute(self, arguments)
|
|
||||||
|
|
||||||
def execute_evaluated(self, *value_list):
|
def execute_evaluated(self, *value_list):
|
||||||
"""
|
"""
|
||||||
Execute a function with already executed arguments.
|
Execute a function with already executed arguments.
|
||||||
"""
|
"""
|
||||||
|
# TODO move this out of here to the evaluator.
|
||||||
from jedi.evaluate.arguments import ValuesArguments
|
from jedi.evaluate.arguments import ValuesArguments
|
||||||
arguments = ValuesArguments([ContextSet(value) for value in value_list])
|
arguments = ValuesArguments([ContextSet(value) for value in value_list])
|
||||||
return self.execute(arguments)
|
return self.evaluator.execute(self, arguments)
|
||||||
|
|
||||||
def iterate(self, contextualized_node=None, is_async=False):
|
def iterate(self, contextualized_node=None, is_async=False):
|
||||||
debug.dbg('iterate %s', self)
|
debug.dbg('iterate %s', self)
|
||||||
@@ -248,6 +236,9 @@ class ContextSet(BaseContextSet):
|
|||||||
[l for l in lazy_contexts if l is not None]
|
[l for l in lazy_contexts if l is not None]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def execute(self, arguments):
|
||||||
|
return ContextSet.from_sets(c.evaluator.execute(c, arguments) for c in self._set)
|
||||||
|
|
||||||
|
|
||||||
NO_CONTEXTS = ContextSet()
|
NO_CONTEXTS = ContextSet()
|
||||||
|
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ class CompiledObject(Context):
|
|||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
bltn_obj = builtin_from_name(self.evaluator, name)
|
bltn_obj = builtin_from_name(self.evaluator, name)
|
||||||
for result in bltn_obj.execute(params):
|
for result in self.evaluator.execute(bltn_obj, params):
|
||||||
yield result
|
yield result
|
||||||
for type_ in docstrings.infer_return_types(self):
|
for type_ in docstrings.infer_return_types(self):
|
||||||
yield type_
|
yield type_
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class AbstractInstanceContext(Context):
|
|||||||
raise AttributeError
|
raise AttributeError
|
||||||
|
|
||||||
def execute(arguments):
|
def execute(arguments):
|
||||||
return ContextSet.from_sets(name.execute(arguments) for name in names)
|
return ContextSet.from_sets(name.infer().execute(arguments) for name in names)
|
||||||
|
|
||||||
return execute
|
return execute
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ from pkg_resources import resource_filename
|
|||||||
from jedi._compatibility import FileNotFoundError
|
from jedi._compatibility import FileNotFoundError
|
||||||
from jedi.plugins.base import BasePlugin
|
from jedi.plugins.base import BasePlugin
|
||||||
from jedi.evaluate.cache import evaluator_as_method_param_cache
|
from jedi.evaluate.cache import evaluator_as_method_param_cache
|
||||||
from jedi.evaluate.base_context import Context, ContextSet
|
from jedi.evaluate.base_context import Context, ContextSet, NO_CONTEXTS
|
||||||
from jedi.evaluate.context import ModuleContext
|
from jedi.evaluate.context import ModuleContext
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +19,8 @@ def _create_stub_map(directory):
|
|||||||
def generate():
|
def generate():
|
||||||
try:
|
try:
|
||||||
listed = os.listdir(directory)
|
listed = os.listdir(directory)
|
||||||
except FileNotFoundError:
|
except (FileNotFoundError, OSError):
|
||||||
|
# OSError is Python 2
|
||||||
return
|
return
|
||||||
|
|
||||||
for entry in listed:
|
for entry in listed:
|
||||||
@@ -85,7 +86,7 @@ class TypeshedPlugin(BasePlugin):
|
|||||||
# ``os``.
|
# ``os``.
|
||||||
mapped = self._cache_stub_file_map(evaluator.grammar.version_info)
|
mapped = self._cache_stub_file_map(evaluator.grammar.version_info)
|
||||||
context_set = callback(evaluator, import_names, module_context, sys_path)
|
context_set = callback(evaluator, import_names, module_context, sys_path)
|
||||||
if len(import_names) == 1:
|
if len(import_names) == 1 and import_names[0] != 'typing':
|
||||||
path = mapped.get(import_names[0])
|
path = mapped.get(import_names[0])
|
||||||
if path is not None:
|
if path is not None:
|
||||||
try:
|
try:
|
||||||
@@ -119,15 +120,25 @@ class StubProxy(object):
|
|||||||
context_results = self._context.py__getattribute__(
|
context_results = self._context.py__getattribute__(
|
||||||
*args, **kwargs
|
*args, **kwargs
|
||||||
)
|
)
|
||||||
typeshed_results = self._stub_context.py__getattribute__(
|
typeshed_results = list(self._stub_context.py__getattribute__(
|
||||||
*args, **kwargs
|
*args, **kwargs
|
||||||
|
))
|
||||||
|
if not typeshed_results:
|
||||||
|
return NO_CONTEXTS
|
||||||
|
|
||||||
|
return ContextSet.from_iterable(
|
||||||
|
StubProxy(c.parent_context, c, typeshed_results[0]) for c in context_results
|
||||||
)
|
)
|
||||||
print()
|
|
||||||
print(context_results, typeshed_results)
|
@property
|
||||||
return context_results
|
def py__call__(self):
|
||||||
|
def py__call__(arguments):
|
||||||
|
return self._stub_context.py__call__(arguments)
|
||||||
|
|
||||||
|
return py__call__
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
return getattr(self._context, name)
|
return getattr(self._context, name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '<%s: %s>' % (type(self).__name__, self.access_handle.get_repr())
|
return '<%s: %s %s>' % (type(self).__name__, self._context, self._stub_context)
|
||||||
|
|||||||
Reference in New Issue
Block a user