From 4176af337f4b921200257109e301303f8408fa82 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Sat, 18 May 2019 01:09:09 +0200 Subject: [PATCH] A few Python 2 fixes --- jedi/evaluate/gradual/typeshed.py | 2 +- jedi/evaluate/syntax_tree.py | 4 ++++ test/completion/stubs.py | 1 + test/test_api/test_api.py | 6 +----- test/test_evaluate/test_gradual/test_typeshed.py | 10 +++++----- test/test_utils.py | 2 +- 6 files changed, 13 insertions(+), 12 deletions(-) diff --git a/jedi/evaluate/gradual/typeshed.py b/jedi/evaluate/gradual/typeshed.py index bc350898..377d270b 100644 --- a/jedi/evaluate/gradual/typeshed.py +++ b/jedi/evaluate/gradual/typeshed.py @@ -234,7 +234,7 @@ def _load_from_typeshed(evaluator, actual_context_set, parent_module_context, im def _try_to_load_stub_from_file(evaluator, actual_context_set, path, import_names): try: stub_module_node = _load_stub(evaluator, path) - except OSError: + except (OSError, IOError): # IOError is Python 2 only # The file that you're looking for doesn't exist (anymore). return None else: diff --git a/jedi/evaluate/syntax_tree.py b/jedi/evaluate/syntax_tree.py index f3f7c015..d3c5d8ee 100644 --- a/jedi/evaluate/syntax_tree.py +++ b/jedi/evaluate/syntax_tree.py @@ -180,6 +180,10 @@ def eval_atom(context, atom): might be a name or a literal as well. """ if atom.type == 'name': + if atom.value in ('True', 'False', 'None'): + # Python 2... + return ContextSet([compiled.builtin_from_name(context.evaluator, atom.value)]) + # This is the first global lookup. stmt = tree.search_ancestor( atom, 'expr_stmt', 'lambdef' diff --git a/test/completion/stubs.py b/test/completion/stubs.py index a99549b0..83013542 100644 --- a/test/completion/stubs.py +++ b/test/completion/stubs.py @@ -1,3 +1,4 @@ +# python >= 3.4 from stub_folder import with_stub, stub_only, with_stub_folder, stub_only_folder # ------------------------- diff --git a/test/test_api/test_api.py b/test/test_api/test_api.py index 5dad960e..b770fd59 100644 --- a/test/test_api/test_api.py +++ b/test/test_api/test_api.py @@ -119,11 +119,7 @@ def test_goto_assignments_on_non_name(Script, environment): assert Script('for').goto_assignments() == [] assert Script('assert').goto_assignments() == [] - if environment.version_info.major == 2: - # In Python 2.7 True is still a name. - assert Script('True').goto_assignments()[0].description == 'instance True' - else: - assert Script('True').goto_assignments() == [] + assert Script('True').goto_assignments() == [] def test_goto_definitions_on_non_name(Script): diff --git a/test/test_evaluate/test_gradual/test_typeshed.py b/test/test_evaluate/test_gradual/test_typeshed.py index 015971d2..8a3a8ac4 100644 --- a/test/test_evaluate/test_gradual/test_typeshed.py +++ b/test/test_evaluate/test_gradual/test_typeshed.py @@ -60,11 +60,11 @@ def test_function(Script, environment): def test_keywords_variable(Script): code = 'import keyword; keyword.kwlist' - seq1, seq2 = Script(code).goto_definitions() - assert seq1.name, seq2.name == 'Sequence' - # This points towards the typeshed implementation - stub_seq, = seq1.goto_stubs() - assert typeshed.TYPESHED_PATH in stub_seq.module_path + for seq in Script(code).goto_definitions(): + assert seq.name == 'Sequence' + # This points towards the typeshed implementation + stub_seq, = seq.goto_stubs() + assert typeshed.TYPESHED_PATH in stub_seq.module_path def test_class(Script): diff --git a/test/test_utils.py b/test/test_utils.py index cc9baf1b..17328a36 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -80,7 +80,7 @@ class TestSetupReadline(unittest.TestCase): difference = {x for x in difference if not x.startswith('from os import _')} # There are quite a few differences, because both Windows and Linux # (posix and nt) libraries are included. - assert len(difference) < 33 + assert len(difference) < 38 @cwd_at('test') def test_local_import(self):