forked from VimPlug/jedi
Move all the gradual typing stuff into one folder
This commit is contained in:
@@ -14,7 +14,7 @@ from jedi.evaluate import imports
|
|||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate.imports import ImportName
|
from jedi.evaluate.imports import ImportName
|
||||||
from jedi.evaluate.context import FunctionExecutionContext
|
from jedi.evaluate.context import FunctionExecutionContext
|
||||||
from jedi.plugins.typeshed import StubOnlyModuleContext
|
from jedi.evaluate.gradual.typeshed import StubOnlyModuleContext
|
||||||
from jedi.api.keywords import KeywordName
|
from jedi.api.keywords import KeywordName
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ class FunctionExecutionContext(TreeContext):
|
|||||||
evaluator = self.evaluator
|
evaluator = self.evaluator
|
||||||
is_coroutine = self.tree_node.parent.type == 'async_stmt'
|
is_coroutine = self.tree_node.parent.type == 'async_stmt'
|
||||||
is_generator = bool(get_yield_exprs(evaluator, self.tree_node))
|
is_generator = bool(get_yield_exprs(evaluator, self.tree_node))
|
||||||
from jedi.evaluate.context.typing import AnnotatedSubClass
|
from jedi.evaluate.gradual.typing import AnnotatedSubClass
|
||||||
|
|
||||||
if is_coroutine:
|
if is_coroutine:
|
||||||
if is_generator:
|
if is_generator:
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ class Sequence(BuiltinOverwrite, IterableMixin):
|
|||||||
|
|
||||||
@memoize_method
|
@memoize_method
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
from jedi.evaluate.context.typing import AnnotatedSubClass
|
from jedi.evaluate.gradual.typing import AnnotatedSubClass
|
||||||
klass = compiled.builtin_from_name(self.evaluator, self.array_type)
|
klass = compiled.builtin_from_name(self.evaluator, self.array_type)
|
||||||
# TODO is this execute annotation wrong? it returns a context set?!
|
# TODO is this execute annotation wrong? it returns a context set?!
|
||||||
return AnnotatedSubClass(klass, self._get_generics()).execute_annotation()
|
return AnnotatedSubClass(klass, self._get_generics()).execute_annotation()
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, TreeContext)):
|
|||||||
)]
|
)]
|
||||||
|
|
||||||
def py__getitem__(self, index_context_set, contextualized_node):
|
def py__getitem__(self, index_context_set, contextualized_node):
|
||||||
from jedi.evaluate.context.typing import AnnotatedClass
|
from jedi.evaluate.gradual.typing import AnnotatedClass
|
||||||
if not index_context_set:
|
if not index_context_set:
|
||||||
return ContextSet([self])
|
return ContextSet([self])
|
||||||
return ContextSet(
|
return ContextSet(
|
||||||
@@ -264,7 +264,7 @@ class ClassContext(use_metaclass(CachedMetaClass, ClassMixin, TreeContext)):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def define_generics(self, type_var_dict):
|
def define_generics(self, type_var_dict):
|
||||||
from jedi.evaluate.context.typing import AnnotatedSubClass
|
from jedi.evaluate.gradual.typing import AnnotatedSubClass
|
||||||
|
|
||||||
def remap_type_vars():
|
def remap_type_vars():
|
||||||
for type_var in self.list_type_vars():
|
for type_var in self.list_type_vars():
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ from jedi.evaluate.filters import GlobalNameFilter, ContextNameMixin, \
|
|||||||
AbstractNameDefinition, ParserTreeFilter, DictFilter, MergedFilter
|
AbstractNameDefinition, ParserTreeFilter, DictFilter, MergedFilter
|
||||||
from jedi.evaluate import compiled
|
from jedi.evaluate import compiled
|
||||||
from jedi.evaluate.base_context import TreeContext
|
from jedi.evaluate.base_context import TreeContext
|
||||||
from jedi.evaluate.imports import SubModuleName, infer_import
|
|
||||||
|
|
||||||
|
|
||||||
class _ModuleAttributeName(AbstractNameDefinition):
|
class _ModuleAttributeName(AbstractNameDefinition):
|
||||||
@@ -84,6 +83,8 @@ class ModuleMixin(object):
|
|||||||
Lists modules in the directory of this module (if this module is a
|
Lists modules in the directory of this module (if this module is a
|
||||||
package).
|
package).
|
||||||
"""
|
"""
|
||||||
|
from jedi.evaluate.imports import SubModuleName
|
||||||
|
|
||||||
names = {}
|
names = {}
|
||||||
try:
|
try:
|
||||||
method = self.py__path__
|
method = self.py__path__
|
||||||
@@ -120,6 +121,8 @@ class ModuleMixin(object):
|
|||||||
# to push the star imports into Evaluator.module_cache, if we reenable this.
|
# to push the star imports into Evaluator.module_cache, if we reenable this.
|
||||||
@evaluator_method_cache([])
|
@evaluator_method_cache([])
|
||||||
def star_imports(self):
|
def star_imports(self):
|
||||||
|
from jedi.evaluate.imports import infer_import
|
||||||
|
|
||||||
modules = []
|
modules = []
|
||||||
for i in self.tree_node.iter_imports():
|
for i in self.tree_node.iter_imports():
|
||||||
if i.is_star_import():
|
if i.is_star_import():
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import os
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
from jedi._compatibility import FileNotFoundError
|
from jedi._compatibility import FileNotFoundError
|
||||||
from jedi.plugins.base import BasePlugin
|
|
||||||
from jedi.evaluate.cache import evaluator_function_cache
|
from jedi.evaluate.cache import evaluator_function_cache
|
||||||
from jedi.cache import memoize_method
|
from jedi.cache import memoize_method
|
||||||
from jedi.parser_utils import get_call_signature_for_any, get_cached_code_lines
|
from jedi.parser_utils import get_call_signature_for_any, get_cached_code_lines
|
||||||
@@ -15,13 +14,12 @@ from jedi.evaluate.context import ModuleContext, FunctionContext, \
|
|||||||
from jedi.evaluate.context.function import FunctionMixin
|
from jedi.evaluate.context.function import FunctionMixin
|
||||||
from jedi.evaluate.context.klass import ClassMixin
|
from jedi.evaluate.context.klass import ClassMixin
|
||||||
from jedi.evaluate.context.module import ModuleMixin
|
from jedi.evaluate.context.module import ModuleMixin
|
||||||
from jedi.evaluate.context.typing import TypingModuleFilterWrapper, \
|
from jedi.evaluate.gradual.typing import TypingModuleFilterWrapper, \
|
||||||
TypingModuleName
|
TypingModuleName
|
||||||
from jedi.evaluate.compiled.context import CompiledName
|
from jedi.evaluate.compiled.context import CompiledName
|
||||||
from jedi.evaluate.utils import to_list, safe_property
|
from jedi.evaluate.utils import to_list, safe_property
|
||||||
from jedi.evaluate.imports import JediImportError
|
|
||||||
|
|
||||||
_jedi_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
_jedi_path = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
_TYPESHED_PATH = os.path.join(_jedi_path, 'third_party', 'typeshed')
|
_TYPESHED_PATH = os.path.join(_jedi_path, 'third_party', 'typeshed')
|
||||||
|
|
||||||
|
|
||||||
@@ -95,10 +93,10 @@ def _merge_modules(context_set, stub_context):
|
|||||||
yield stub_context
|
yield stub_context
|
||||||
|
|
||||||
|
|
||||||
class TypeshedPlugin(BasePlugin):
|
_version_cache = {}
|
||||||
_version_cache = {}
|
|
||||||
|
|
||||||
def _cache_stub_file_map(self, version_info):
|
|
||||||
|
def _cache_stub_file_map(version_info):
|
||||||
"""
|
"""
|
||||||
Returns a map of an importable name in Python to a stub file.
|
Returns a map of an importable name in Python to a stub file.
|
||||||
"""
|
"""
|
||||||
@@ -106,15 +104,16 @@ class TypeshedPlugin(BasePlugin):
|
|||||||
# for that?
|
# for that?
|
||||||
version = version_info[:2]
|
version = version_info[:2]
|
||||||
try:
|
try:
|
||||||
return self._version_cache[version]
|
return _version_cache[version]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
self._version_cache[version] = file_set = \
|
_version_cache[version] = file_set = \
|
||||||
_merge_create_stub_map(_get_typeshed_directories(version_info))
|
_merge_create_stub_map(_get_typeshed_directories(version_info))
|
||||||
return file_set
|
return file_set
|
||||||
|
|
||||||
def import_module(self, callback):
|
|
||||||
|
def import_module_decorator(func):
|
||||||
def wrapper(evaluator, import_names, parent_module_context, sys_path):
|
def wrapper(evaluator, import_names, parent_module_context, sys_path):
|
||||||
if import_names == ('_sqlite3',):
|
if import_names == ('_sqlite3',):
|
||||||
# TODO Maybe find a better solution for this?
|
# TODO Maybe find a better solution for this?
|
||||||
@@ -131,8 +130,9 @@ class TypeshedPlugin(BasePlugin):
|
|||||||
parent_module_context, = evaluator.import_module(('os',))
|
parent_module_context, = evaluator.import_module(('os',))
|
||||||
return parent_module_context.py__getattribute__('path')
|
return parent_module_context.py__getattribute__('path')
|
||||||
|
|
||||||
|
from jedi.evaluate.imports import JediImportError
|
||||||
try:
|
try:
|
||||||
context_set = callback(
|
context_set = func(
|
||||||
evaluator,
|
evaluator,
|
||||||
import_names,
|
import_names,
|
||||||
parent_module_context,
|
parent_module_context,
|
||||||
@@ -148,7 +148,7 @@ class TypeshedPlugin(BasePlugin):
|
|||||||
import_name = import_names[-1]
|
import_name = import_names[-1]
|
||||||
map_ = None
|
map_ = None
|
||||||
if len(import_names) == 1:
|
if len(import_names) == 1:
|
||||||
map_ = self._cache_stub_file_map(evaluator.grammar.version_info)
|
map_ = _cache_stub_file_map(evaluator.grammar.version_info)
|
||||||
elif isinstance(parent_module_context, StubModuleContext):
|
elif isinstance(parent_module_context, StubModuleContext):
|
||||||
if not parent_module_context.stub_context.is_package():
|
if not parent_module_context.stub_context.is_package():
|
||||||
# Only if it's a package (= a folder) something can be
|
# Only if it's a package (= a folder) something can be
|
||||||
@@ -2,6 +2,8 @@
|
|||||||
We need to somehow work with the typing objects. Since the typing objects are
|
We need to somehow work with the typing objects. Since the typing objects are
|
||||||
pretty bare we need to add all the Jedi customizations to make them work as
|
pretty bare we need to add all the Jedi customizations to make them work as
|
||||||
contexts.
|
contexts.
|
||||||
|
|
||||||
|
This file deals with all the typing.py cases.
|
||||||
"""
|
"""
|
||||||
from jedi._compatibility import unicode, force_unicode
|
from jedi._compatibility import unicode, force_unicode
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
@@ -16,7 +18,6 @@ from jedi.evaluate.utils import to_list
|
|||||||
from jedi.evaluate.filters import FilterWrapper, NameWrapper, \
|
from jedi.evaluate.filters import FilterWrapper, NameWrapper, \
|
||||||
AbstractTreeName, AbstractNameDefinition, ContextName
|
AbstractTreeName, AbstractNameDefinition, ContextName
|
||||||
from jedi.evaluate.helpers import is_string
|
from jedi.evaluate.helpers import is_string
|
||||||
from jedi.evaluate.imports import Importer
|
|
||||||
from jedi.evaluate.context.klass import ClassMixin
|
from jedi.evaluate.context.klass import ClassMixin
|
||||||
|
|
||||||
_PROXY_CLASS_TYPES = 'Tuple Generic Protocol Callable Type'.split()
|
_PROXY_CLASS_TYPES = 'Tuple Generic Protocol Callable Type'.split()
|
||||||
@@ -261,6 +262,8 @@ class TypeAlias(HelperContextMixin):
|
|||||||
if self.evaluator.environment.version_info.major == 2 and module_name == 'builtins':
|
if self.evaluator.environment.version_info.major == 2 and module_name == 'builtins':
|
||||||
module_name = '__builtin__'
|
module_name = '__builtin__'
|
||||||
|
|
||||||
|
# TODO use evaluator.import_module?
|
||||||
|
from jedi.evaluate.imports import Importer
|
||||||
module, = Importer(
|
module, = Importer(
|
||||||
self.evaluator, [module_name], self.evaluator.builtins_module
|
self.evaluator, [module_name], self.evaluator.builtins_module
|
||||||
).follow()
|
).follow()
|
||||||
@@ -30,6 +30,7 @@ from jedi.evaluate.utils import unite
|
|||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.evaluate.filters import AbstractNameDefinition
|
from jedi.evaluate.filters import AbstractNameDefinition
|
||||||
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS
|
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS
|
||||||
|
from jedi.evaluate.gradual.typeshed import import_module_decorator
|
||||||
|
|
||||||
|
|
||||||
class ModuleCache(object):
|
class ModuleCache(object):
|
||||||
@@ -387,6 +388,7 @@ class JediImportError(Exception):
|
|||||||
self.import_names = import_names
|
self.import_names = import_names
|
||||||
|
|
||||||
|
|
||||||
|
@import_module_decorator
|
||||||
def import_module(evaluator, import_names, parent_module_context, sys_path):
|
def import_module(evaluator, import_names, parent_module_context, sys_path):
|
||||||
"""
|
"""
|
||||||
This method is very similar to importlib's `_gcd_import`.
|
This method is very similar to importlib's `_gcd_import`.
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ from parso import ParserSyntaxError, parse
|
|||||||
from jedi._compatibility import force_unicode
|
from jedi._compatibility import force_unicode
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS
|
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS
|
||||||
from jedi.evaluate.context.typing import TypeVar, AnnotatedClass, \
|
from jedi.evaluate.gradual.typing import TypeVar, AnnotatedClass, \
|
||||||
AbstractAnnotatedClass
|
AbstractAnnotatedClass
|
||||||
from jedi.evaluate.helpers import is_string
|
from jedi.evaluate.helpers import is_string
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ from jedi.evaluate.finder import NameFinder
|
|||||||
from jedi.evaluate.helpers import is_string, is_literal, is_number, is_compiled
|
from jedi.evaluate.helpers import is_string, is_literal, is_number, is_compiled
|
||||||
from jedi.evaluate.compiled.access import COMPARISON_OPERATORS
|
from jedi.evaluate.compiled.access import COMPARISON_OPERATORS
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
|
from jedi.evaluate.gradual.typeshed import VersionInfo
|
||||||
|
|
||||||
|
|
||||||
def _limit_context_infers(func):
|
def _limit_context_infers(func):
|
||||||
@@ -495,7 +496,6 @@ def _eval_comparison_part(evaluator, context, left, operator, right):
|
|||||||
bool_ = operation(left, right)
|
bool_ = operation(left, right)
|
||||||
return ContextSet([_bool_to_context(evaluator, bool_)])
|
return ContextSet([_bool_to_context(evaluator, bool_)])
|
||||||
|
|
||||||
from jedi.plugins.typeshed import VersionInfo
|
|
||||||
if isinstance(left, VersionInfo):
|
if isinstance(left, VersionInfo):
|
||||||
version_info = _get_tuple_ints(right)
|
version_info = _get_tuple_ints(right)
|
||||||
if version_info is not None:
|
if version_info is not None:
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from jedi.plugins.stdlib import StdlibPlugin
|
from jedi.plugins.stdlib import StdlibPlugin
|
||||||
from jedi.plugins.typeshed import TypeshedPlugin
|
|
||||||
from jedi.plugins.flask import FlaskPlugin
|
from jedi.plugins.flask import FlaskPlugin
|
||||||
|
|
||||||
|
|
||||||
@@ -35,5 +34,4 @@ class _PluginCallbacks(object):
|
|||||||
plugin_manager = _PluginManager([
|
plugin_manager = _PluginManager([
|
||||||
StdlibPlugin,
|
StdlibPlugin,
|
||||||
FlaskPlugin,
|
FlaskPlugin,
|
||||||
TypeshedPlugin,
|
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from pytest import raises
|
|||||||
from parso import cache
|
from parso import cache
|
||||||
|
|
||||||
from jedi import preload_module
|
from jedi import preload_module
|
||||||
from jedi.plugins import typeshed
|
from jedi.evaluate.gradual import typeshed
|
||||||
|
|
||||||
|
|
||||||
def test_preload_modules():
|
def test_preload_modules():
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from jedi.plugins import typeshed
|
from jedi.evaluate.gradual import typeshed
|
||||||
from jedi.evaluate.context import TreeInstance, BoundMethod, FunctionContext
|
from jedi.evaluate.context import TreeInstance, BoundMethod, FunctionContext
|
||||||
from parso.utils import PythonVersionInfo
|
from parso.utils import PythonVersionInfo
|
||||||
from jedi.evaluate.filters import TreeNameDefinition
|
from jedi.evaluate.filters import TreeNameDefinition
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import pytest
|
|||||||
from jedi import settings
|
from jedi import settings
|
||||||
from jedi.evaluate.filters import ContextName
|
from jedi.evaluate.filters import ContextName
|
||||||
from jedi.evaluate.compiled import CompiledContextName
|
from jedi.evaluate.compiled import CompiledContextName
|
||||||
from jedi.plugins.typeshed import StubOnlyModuleContext
|
from jedi.evaluate.gradual.typeshed import StubOnlyModuleContext
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|||||||
Reference in New Issue
Block a user