1
0
forked from VimPlug/jedi

Get rid of a few Python 2 things

This commit is contained in:
Dave Halter
2020-07-02 16:00:26 +02:00
parent ec08506704
commit dac1fb0a06
3 changed files with 6 additions and 8 deletions

View File

@@ -1,6 +1,5 @@
import sys import sys
import os import os
import re
import inspect import inspect
import importlib import importlib
import warnings import warnings
@@ -102,10 +101,9 @@ def _iter_module_names(inference_state, paths):
name = dir_entry.name name = dir_entry.name
# First Namespaces then modules/stubs # First Namespaces then modules/stubs
if dir_entry.is_dir(): if dir_entry.is_dir():
# pycache is obviously not an interestin namespace. Also the # pycache is obviously not an interesting namespace. Also the
# name must be a valid identifier. # name must be a valid identifier.
# TODO use str.isidentifier, once Python 2 is removed if name != '__pycache__' and name.isidentifier():
if name != '__pycache__' and not re.search(r'\W|^\d', name):
yield name yield name
else: else:
if name.endswith('.pyi'): # Stub files if name.endswith('.pyi'): # Stub files

View File

@@ -138,8 +138,7 @@ def _infer_param(function_value, param):
""" """
annotation = param.annotation annotation = param.annotation
if annotation is None: if annotation is None:
# If no Python 3-style annotation, look for a Python 2-style comment # If no Python 3-style annotation, look for a comment annotation.
# annotation.
# Identify parameters to function in the same sequence as they would # Identify parameters to function in the same sequence as they would
# appear in a type comment. # appear in a type comment.
all_params = [child for child in param.parent.children all_params = [child for child in param.parent.children
@@ -204,7 +203,8 @@ def infer_return_types(function, arguments):
all_annotations = py__annotations__(function.tree_node) all_annotations = py__annotations__(function.tree_node)
annotation = all_annotations.get("return", None) annotation = all_annotations.get("return", None)
if annotation is None: if annotation is None:
# If there is no Python 3-type annotation, look for a Python 2-type annotation # If there is no Python 3-type annotation, look for an annotation
# comment.
node = function.tree_node node = function.tree_node
comment = parser_utils.get_following_comment_same_line(node) comment = parser_utils.get_following_comment_same_line(node)
if comment is None: if comment is None:

View File

@@ -272,7 +272,7 @@ def _load_from_typeshed(inference_state, python_value_set, parent_module_value,
def _try_to_load_stub_from_file(inference_state, python_value_set, file_io, import_names): def _try_to_load_stub_from_file(inference_state, python_value_set, file_io, import_names):
try: try:
stub_module_node = parse_stub_module(inference_state, file_io) stub_module_node = parse_stub_module(inference_state, file_io)
except OSError: # IOError is Python 2 only except OSError:
# The file that you're looking for doesn't exist (anymore). # The file that you're looking for doesn't exist (anymore).
return None return None
else: else: