Remove some more Python 3.5 references

This commit is contained in:
Dave Halter
2020-07-02 02:13:06 +02:00
parent 182e1e864c
commit 17343bb57c
9 changed files with 52 additions and 95 deletions

View File

@@ -1,18 +1,9 @@
import pydoc import pydoc
from contextlib import suppress
from jedi.inference.utils import ignored
from jedi.inference.names import AbstractArbitraryName from jedi.inference.names import AbstractArbitraryName
try: from pydoc_data import topics as pydoc_topics
from pydoc_data import topics as pydoc_topics
except ImportError:
# Python 2
try:
import pydoc_topics
except ImportError:
# This is for Python 3 embeddable version, which dont have
# pydoc_data module in its file python3x.zip.
pydoc_topics = None
class KeywordName(AbstractArbitraryName): class KeywordName(AbstractArbitraryName):
@@ -34,7 +25,7 @@ def imitate_pydoc(string):
# with unicode strings) # with unicode strings)
string = str(string) string = str(string)
h = pydoc.help h = pydoc.help
with ignored(KeyError): with suppress(KeyError):
# try to access symbols # try to access symbols
string = h.symbols[string] string = h.symbols[string]
string, _, related = string.partition(' ') string, _, related = string.partition(' ')

View File

@@ -10,7 +10,6 @@ be used across repositories.
import os import os
import errno import errno
import json import json
import sys
from jedi import debug from jedi import debug
from jedi.api.environment import get_cached_default_environment, create_environment from jedi.api.environment import get_cached_default_environment, create_environment
@@ -258,10 +257,6 @@ class Project(object):
inference_state = s._inference_state inference_state = s._inference_state
empty_module_context = s._get_module_context() empty_module_context = s._get_module_context()
if inference_state.grammar.version_info < (3, 6) or sys.version_info < (3, 6):
raise NotImplementedError(
"No support for refactorings/search on Python 2/3.5"
)
debug.dbg('Search for string %s, complete=%s', string, complete) debug.dbg('Search for string %s, complete=%s', string, complete)
wanted_type, wanted_names = split_search_string(string) wanted_type, wanted_names = split_search_string(string)
name = wanted_names[0] name = wanted_names[0]

View File

@@ -142,11 +142,8 @@ def unpack_arglist(arglist):
if arglist is None: if arglist is None:
return return
# Allow testlist here as well for Python2's class inheritance if arglist.type != 'arglist' and not (
# definitions. arglist.type == 'argument' and arglist.children[0] in ('*', '**')):
if not (arglist.type in ('arglist', 'testlist') or (
# in python 3.5 **arg is an argument, not arglist
arglist.type == 'argument' and arglist.children[0] in ('*', '**'))):
yield 0, arglist yield 0, arglist
return return

View File

@@ -8,7 +8,7 @@ import warnings
import re import re
import builtins import builtins
from jedi._compatibility import unicode, is_py3, py_version from jedi._compatibility import unicode, py_version
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)
@@ -28,17 +28,12 @@ NOT_CLASS_TYPES = (
types.MethodType, types.MethodType,
types.ModuleType, types.ModuleType,
types.TracebackType, types.TracebackType,
MethodDescriptorType MethodDescriptorType,
types.MappingProxyType,
types.SimpleNamespace,
types.DynamicClassAttribute,
) )
if is_py3:
NOT_CLASS_TYPES += (
types.MappingProxyType,
types.SimpleNamespace,
types.DynamicClassAttribute,
)
# Those types don't exist in typing. # Those types don't exist in typing.
MethodDescriptorType = type(str.replace) MethodDescriptorType = type(str.replace)
WrapperDescriptorType = type(set.__iter__) WrapperDescriptorType = type(set.__iter__)

View File

@@ -14,7 +14,7 @@ def load_proper_stub_module(inference_state, file_io, import_names, module_node)
# /foo/stdlib/3/os/__init__.pyi -> stdlib/3/os/__init__ # /foo/stdlib/3/os/__init__.pyi -> stdlib/3/os/__init__
rest = path[len(TYPESHED_PATH) + 1: -4] rest = path[len(TYPESHED_PATH) + 1: -4]
split_paths = tuple(rest.split(os.path.sep)) split_paths = tuple(rest.split(os.path.sep))
# Remove the stdlib/3 or third_party/3.5 part # Remove the stdlib/3 or third_party/3.6 part
import_names = split_paths[2:] import_names = split_paths[2:]
if import_names[-1] == '__init__': if import_names[-1] == '__init__':
import_names = import_names[:-1] import_names = import_names[:-1]

View File

@@ -12,7 +12,7 @@ from jedi._compatibility import unicode
def is_stdlib_path(path): def is_stdlib_path(path):
# Python standard library paths look like this: # Python standard library paths look like this:
# /usr/lib/python3.5/... # /usr/lib/python3.9/...
# TODO The implementation below is probably incorrect and not complete. # TODO The implementation below is probably incorrect and not complete.
if 'dist-packages' in path or 'site-packages' in path: if 'dist-packages' in path or 'site-packages' in path:
return False return False

View File

@@ -99,15 +99,3 @@ class PushBackIterator(object):
else: else:
self.current = next(self.iterator) self.current = next(self.iterator)
return self.current return self.current
@contextlib.contextmanager
def ignored(*exceptions):
"""
Value manager that ignores all of the specified exceptions. This will
be in the standard library starting with Python 3.5.
"""
try:
yield
except exceptions:
pass

View File

@@ -4,7 +4,6 @@ iterators in general.
""" """
import sys import sys
from jedi._compatibility import is_py3
from jedi.inference import compiled from jedi.inference import compiled
from jedi.inference import analysis from jedi.inference import analysis
from jedi.inference.lazy_value import LazyKnownValue, LazyKnownValues, \ from jedi.inference.lazy_value import LazyKnownValue, LazyKnownValues, \

View File

@@ -133,48 +133,6 @@ weakref.ref(1)
#? int() None #? int() None
weakref.ref(1)() weakref.ref(1)()
# -----------------
# functools
# -----------------
import functools
basetwo = functools.partial(int, base=2)
#? int()
basetwo()
def function(a, b):
return a, b
a = functools.partial(function, 0)
#? int()
a('')[0]
#? str()
a('')[1]
kw = functools.partial(function, b=1.0)
tup = kw(1)
#? int()
tup[0]
#? float()
tup[1]
def my_decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwds):
return f(*args, **kwds)
return wrapper
@my_decorator
def example(a):
return a
#? str()
example('')
# From GH #1574
#? float()
functools.wraps(functools.partial(str, 1))(lambda: 1.0)()
# ----------------- # -----------------
# sqlite3 (#84) # sqlite3 (#84)
# ----------------- # -----------------
@@ -386,8 +344,47 @@ X().name
X().attr_x.attr_y.value X().attr_x.attr_y.value
# ----------------- # -----------------
# functools Python 3.5+ # functools
# ----------------- # -----------------
import functools
basetwo = functools.partial(int, base=2)
#? int()
basetwo()
def function(a, b):
return a, b
a = functools.partial(function, 0)
#? int()
a('')[0]
#? str()
a('')[1]
kw = functools.partial(function, b=1.0)
tup = kw(1)
#? int()
tup[0]
#? float()
tup[1]
def my_decorator(f):
@functools.wraps(f)
def wrapper(*args, **kwds):
return f(*args, **kwds)
return wrapper
@my_decorator
def example(a):
return a
#? str()
example('')
# From GH #1574
#? float()
functools.wraps(functools.partial(str, 1))(lambda: 1.0)()
class X: class X:
def function(self, a, b): def function(self, a, b):
return a, b return a, b
@@ -440,11 +437,6 @@ X().just_partial('')[0]
#? str() #? str()
X().just_partial('')[1] X().just_partial('')[1]
# -----------------
# functools Python 3.8
# -----------------
# python >= 3.8 # python >= 3.8
@functools.lru_cache @functools.lru_cache