1
0
forked from VimPlug/jedi

Fix the compatibility docstring

This commit is contained in:
Dave Halter
2020-07-02 01:58:38 +02:00
parent 9838040ca3
commit 782c561e86
12 changed files with 13 additions and 33 deletions

View File

@@ -1,6 +1,6 @@
""" """
To ensure compatibility from Python ``2.7`` - ``3.x``, a module has been This module is here to ensure compatibility of Windows/Linux/MacOS and
created. Clearly there is huge need to use conforming syntax. different Python versions.
""" """
from __future__ import print_function from __future__ import print_function
import errno import errno

View File

@@ -94,7 +94,7 @@ class BaseName(object):
@property @property
def module_path(self): def module_path(self):
""" """
Shows the file path of a module. e.g. ``/usr/lib/python2.7/os.py`` Shows the file path of a module. e.g. ``/usr/lib/python3.9/os.py``
:rtype: str or None :rtype: str or None
""" """

View File

@@ -9,7 +9,7 @@ just use IPython instead::
Then you will be able to use Jedi completer in your Python interpreter:: Then you will be able to use Jedi completer in your Python interpreter::
$ python $ python
Python 2.7.2+ (default, Jul 20 2012, 22:15:08) Python 3.9.2+ (default, Jul 20 2020, 22:15:08)
[GCC 4.6.1] on linux2 [GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information. Type "help", "copyright", "credits" or "license" for more information.
>>> import os >>> import os

View File

@@ -201,11 +201,8 @@ def _infer_for_statement_string(module_context, string):
# (e.g., 'threading' in 'threading.Thread'). # (e.g., 'threading' in 'threading.Thread').
string = 'import %s\n' % element + string string = 'import %s\n' % element + string
# Take the default grammar here, if we load the Python 2.7 grammar here, it
# will be impossible to use `...` (Ellipsis) as a token. Docstring types
# don't need to conform with the current grammar.
debug.dbg('Parse docstring code %s', string, color='BLUE') debug.dbg('Parse docstring code %s', string, color='BLUE')
grammar = module_context.inference_state.latest_grammar grammar = module_context.inference_state.grammar
try: try:
module = grammar.parse(code.format(indent_block(string)), error_recovery=False) module = grammar.parse(code.format(indent_block(string)), error_recovery=False)
except ParserSyntaxError: except ParserSyntaxError:

View File

@@ -32,8 +32,6 @@ def _iter_nodes_for_param(param_name):
argument = name.parent argument = name.parent
if argument.type == 'argument' \ if argument.type == 'argument' \
and argument.children[0] == '*' * param_name.star_count: and argument.children[0] == '*' * param_name.star_count:
# No support for Python 2.7 here, but they are end-of-life
# anyway
trailer = search_ancestor(argument, 'trailer') trailer = search_ancestor(argument, 'trailer')
if trailer is not None: # Make sure we're in a function if trailer is not None: # Make sure we're in a function
context = execution_context.create_context(trailer) context = execution_context.create_context(trailer)

View File

@@ -312,9 +312,6 @@ def infer_atom(context, atom):
# For False/True/None # For False/True/None
if atom.value in ('False', 'True', 'None'): if atom.value in ('False', 'True', 'None'):
return ValueSet([compiled.builtin_from_name(state, atom.value)]) return ValueSet([compiled.builtin_from_name(state, atom.value)])
elif atom.value == 'print':
# print e.g. could be inferred like this in Python 2.7
return NO_VALUES
elif atom.value == 'yield': elif atom.value == 'yield':
# Contrary to yield from, yield can just appear alone to return a # Contrary to yield from, yield can just appear alone to return a
# value when used with `.send()`. # value when used with `.send()`.

View File

@@ -3,15 +3,8 @@ A helper module for testing, improves compatibility for testing (as
``jedi._compatibility``) as well as introducing helper functions. ``jedi._compatibility``) as well as introducing helper functions.
""" """
import sys
from contextlib import contextmanager from contextlib import contextmanager
if sys.hexversion < 0x02070000:
import unittest2 as unittest
else:
import unittest
TestCase = unittest.TestCase
import os import os
import pytest import pytest
from os.path import abspath, dirname, join from os.path import abspath, dirname, join

View File

@@ -1,10 +1,10 @@
import sys import sys
from textwrap import dedent from textwrap import dedent
import inspect import inspect
from unittest import TestCase
import pytest import pytest
from ..helpers import TestCase
from jedi import cache from jedi import cache
from jedi.parser_utils import get_signature from jedi.parser_utils import get_signature
from jedi import Interpreter from jedi import Interpreter

View File

@@ -14,11 +14,11 @@ There are three kinds of test:
""" """
import textwrap import textwrap
from unittest import TestCase
import pytest import pytest
import jedi import jedi
from ..helpers import TestCase
class MixinTestFullName(object): class MixinTestFullName(object):

View File

@@ -2,26 +2,25 @@
""" """
All character set and unicode related tests. All character set and unicode related tests.
""" """
from jedi._compatibility import u, unicode from jedi._compatibility import u
from jedi import Project from jedi import Project
def test_unicode_script(Script): def test_unicode_script(Script):
""" normally no unicode objects are being used. (<=2.7) """ s = "import datetime; datetime.timedelta"
s = unicode("import datetime; datetime.timedelta")
completions = Script(s).complete() completions = Script(s).complete()
assert len(completions) assert len(completions)
assert type(completions[0].description) is unicode assert type(completions[0].description) is str
s = u("author='öä'; author") s = u("author='öä'; author")
completions = Script(s).complete() completions = Script(s).complete()
x = completions[0].description x = completions[0].description
assert type(x) is unicode assert type(x) is str
s = u("#-*- coding: iso-8859-1 -*-\nauthor='öä'; author") s = u("#-*- coding: iso-8859-1 -*-\nauthor='öä'; author")
s = s.encode('latin-1') s = s.encode('latin-1')
completions = Script(s).complete() completions = Script(s).complete()
assert type(completions[0].description) is unicode assert type(completions[0].description) is str
def test_unicode_attribute(Script): def test_unicode_attribute(Script):

View File

@@ -87,9 +87,6 @@ def test_tokenizer_with_string_literal_backslash(Script):
def test_ellipsis_without_getitem(Script, environment): def test_ellipsis_without_getitem(Script, environment):
if environment.version_info.major == 2:
pytest.skip('In 2.7 Ellipsis can only be used like x[...]')
def_, = Script('x=...;x').infer() def_, = Script('x=...;x').infer()
assert def_.name == 'ellipsis' assert def_.name == 'ellipsis'

View File

@@ -2,11 +2,10 @@ try:
import readline import readline
except ImportError: except ImportError:
readline = False readline = False
import unittest
from jedi import utils from jedi import utils
from .helpers import unittest
@unittest.skipIf(not readline, "readline not found") @unittest.skipIf(not readline, "readline not found")
class TestSetupReadline(unittest.TestCase): class TestSetupReadline(unittest.TestCase):