mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Remove the __builtin__ compatibility
This commit is contained in:
@@ -198,12 +198,6 @@ def force_unicode(obj):
|
|||||||
return cast_path(obj)
|
return cast_path(obj)
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
import builtins # module name in python 3
|
|
||||||
except ImportError:
|
|
||||||
import __builtin__ as builtins # noqa: F401
|
|
||||||
|
|
||||||
|
|
||||||
def utf8_repr(func):
|
def utf8_repr(func):
|
||||||
"""
|
"""
|
||||||
``__repr__`` methods in Python 2 don't allow unicode objects to be
|
``__repr__`` methods in Python 2 don't allow unicode objects to be
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ class Script(object):
|
|||||||
code_lines=self._code_lines,
|
code_lines=self._code_lines,
|
||||||
is_package=is_package,
|
is_package=is_package,
|
||||||
)
|
)
|
||||||
if names[0] not in ('builtins', '__builtin__', 'typing'):
|
if names[0] not in ('builtins', 'typing'):
|
||||||
# These modules are essential for Jedi, so don't overwrite them.
|
# These modules are essential for Jedi, so don't overwrite them.
|
||||||
self._inference_state.module_cache.add(names, ValueSet([module]))
|
self._inference_state.module_cache.add(names, ValueSet([module]))
|
||||||
return module
|
return module
|
||||||
|
|||||||
@@ -70,7 +70,6 @@ class BaseName(object):
|
|||||||
'_collections': 'collections',
|
'_collections': 'collections',
|
||||||
'_socket': 'socket',
|
'_socket': 'socket',
|
||||||
'_sqlite3': 'sqlite3',
|
'_sqlite3': 'sqlite3',
|
||||||
'__builtin__': 'builtins',
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_tuple_mapping = dict((tuple(k.split('.')), v) for (k, v) in {
|
_tuple_mapping = dict((tuple(k.split('.')), v) for (k, v) in {
|
||||||
|
|||||||
@@ -124,8 +124,6 @@ class InferenceState(object):
|
|||||||
@inference_state_function_cache()
|
@inference_state_function_cache()
|
||||||
def builtins_module(self):
|
def builtins_module(self):
|
||||||
module_name = u'builtins'
|
module_name = u'builtins'
|
||||||
if self.environment.version_info.major == 2:
|
|
||||||
module_name = u'__builtin__'
|
|
||||||
builtins_module, = self.import_module((module_name,), sys_path=())
|
builtins_module, = self.import_module((module_name,), sys_path=())
|
||||||
return builtins_module
|
return builtins_module
|
||||||
|
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import operator as op
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
import warnings
|
import warnings
|
||||||
import re
|
import re
|
||||||
|
import builtins
|
||||||
|
|
||||||
from jedi._compatibility import unicode, is_py3, builtins, \
|
from jedi._compatibility import unicode, is_py3, py_version, force_unicode
|
||||||
py_version, force_unicode
|
|
||||||
from jedi.inference.compiled.getattr_static import getattr_static
|
from jedi.inference.compiled.getattr_static import getattr_static
|
||||||
|
|
||||||
ALLOWED_GETITEM_TYPES = (str, list, tuple, unicode, bytes, bytearray, dict)
|
ALLOWED_GETITEM_TYPES = (str, list, tuple, unicode, bytes, bytearray, dict)
|
||||||
@@ -267,19 +267,17 @@ class DirectObjectAccess(object):
|
|||||||
@_force_unicode_decorator
|
@_force_unicode_decorator
|
||||||
@shorten_repr
|
@shorten_repr
|
||||||
def get_repr(self):
|
def get_repr(self):
|
||||||
builtins = 'builtins', '__builtin__'
|
|
||||||
|
|
||||||
if inspect.ismodule(self._obj):
|
if inspect.ismodule(self._obj):
|
||||||
return repr(self._obj)
|
return repr(self._obj)
|
||||||
# Try to avoid execution of the property.
|
# Try to avoid execution of the property.
|
||||||
if safe_getattr(self._obj, '__module__', default='') in builtins:
|
if safe_getattr(self._obj, '__module__', default='') == 'builtins':
|
||||||
return repr(self._obj)
|
return repr(self._obj)
|
||||||
|
|
||||||
type_ = type(self._obj)
|
type_ = type(self._obj)
|
||||||
if type_ == type:
|
if type_ == type:
|
||||||
return type.__repr__(self._obj)
|
return type.__repr__(self._obj)
|
||||||
|
|
||||||
if safe_getattr(type_, '__module__', default='') in builtins:
|
if safe_getattr(type_, '__module__', default='') == 'builtins':
|
||||||
# Allow direct execution of repr for builtins.
|
# Allow direct execution of repr for builtins.
|
||||||
return repr(self._obj)
|
return repr(self._obj)
|
||||||
return object.__repr__(self._obj)
|
return object.__repr__(self._obj)
|
||||||
|
|||||||
@@ -263,8 +263,6 @@ class TypeAlias(LazyValueWrapper):
|
|||||||
|
|
||||||
def _get_wrapped_value(self):
|
def _get_wrapped_value(self):
|
||||||
module_name, class_name = self._actual.split('.')
|
module_name, class_name = self._actual.split('.')
|
||||||
if self.inference_state.environment.version_info.major == 2 and module_name == 'builtins':
|
|
||||||
module_name = '__builtin__'
|
|
||||||
|
|
||||||
# TODO use inference_state.import_module?
|
# TODO use inference_state.import_module?
|
||||||
from jedi.inference.imports import Importer
|
from jedi.inference.imports import Importer
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ def test_keyword_attributes(Script):
|
|||||||
assert def_.full_name is None
|
assert def_.full_name is None
|
||||||
assert def_.line is def_.column is None
|
assert def_.line is def_.column is None
|
||||||
assert def_.in_builtin_module() is True
|
assert def_.in_builtin_module() is True
|
||||||
assert def_.module_name in ('builtins', '__builtin__')
|
assert def_.module_name == 'builtins'
|
||||||
assert 'typeshed' in def_.module_path
|
assert 'typeshed' in def_.module_path
|
||||||
assert def_.type == 'keyword'
|
assert def_.type == 'keyword'
|
||||||
|
|
||||||
|
|||||||
@@ -142,8 +142,6 @@ def test_parent_context(same_process_inference_state, attribute, expected_name,
|
|||||||
x, = o.py__getattribute__(attribute)
|
x, = o.py__getattribute__(attribute)
|
||||||
assert x.py__name__() == expected_name
|
assert x.py__name__() == expected_name
|
||||||
module_name = x.parent_context.py__name__()
|
module_name = x.parent_context.py__name__()
|
||||||
if module_name == '__builtin__':
|
|
||||||
module_name = 'builtins' # Python 2
|
|
||||||
assert module_name == expected_parent
|
assert module_name == expected_parent
|
||||||
assert x.parent_context.parent_context is None
|
assert x.parent_context.parent_context is None
|
||||||
|
|
||||||
|
|||||||
@@ -432,9 +432,6 @@ def test_import_name_calculation(Script):
|
|||||||
|
|
||||||
@pytest.mark.parametrize('name', ('builtins', 'typing'))
|
@pytest.mark.parametrize('name', ('builtins', 'typing'))
|
||||||
def test_pre_defined_imports_module(Script, environment, name):
|
def test_pre_defined_imports_module(Script, environment, name):
|
||||||
if environment.version_info.major < 3 and name == 'builtins':
|
|
||||||
name = '__builtin__'
|
|
||||||
|
|
||||||
path = os.path.join(root_dir, name + '.py')
|
path = os.path.join(root_dir, name + '.py')
|
||||||
module = Script('', path=path)._get_module_context()
|
module = Script('', path=path)._get_module_context()
|
||||||
assert module.string_names == (name,)
|
assert module.string_names == (name,)
|
||||||
@@ -445,9 +442,6 @@ def test_pre_defined_imports_module(Script, environment, name):
|
|||||||
|
|
||||||
@pytest.mark.parametrize('name', ('builtins', 'typing'))
|
@pytest.mark.parametrize('name', ('builtins', 'typing'))
|
||||||
def test_import_needed_modules_by_jedi(Script, environment, tmpdir, name):
|
def test_import_needed_modules_by_jedi(Script, environment, tmpdir, name):
|
||||||
if environment.version_info.major < 3 and name == 'builtins':
|
|
||||||
name = '__builtin__'
|
|
||||||
|
|
||||||
module_path = tmpdir.join(name + '.py')
|
module_path = tmpdir.join(name + '.py')
|
||||||
module_path.write('int = ...')
|
module_path.write('int = ...')
|
||||||
script = Script(
|
script = Script(
|
||||||
|
|||||||
Reference in New Issue
Block a user