mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 06:24:27 +08:00
Some more code quality fixes
This commit is contained in:
@@ -27,8 +27,8 @@ def _start_linter():
|
|||||||
paths = [path]
|
paths = [path]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for path in paths:
|
for p in paths:
|
||||||
for error in jedi.Script(path=path)._analysis():
|
for error in jedi.Script(path=p)._analysis():
|
||||||
print(error)
|
print(error)
|
||||||
except Exception:
|
except Exception:
|
||||||
if '--pdb' in sys.argv:
|
if '--pdb' in sys.argv:
|
||||||
|
|||||||
@@ -186,7 +186,6 @@ def find_module_pre_py3(string, path=None, full_name=None, is_global_search=True
|
|||||||
module_file = None
|
module_file = None
|
||||||
|
|
||||||
if module_file is None:
|
if module_file is None:
|
||||||
code = None
|
|
||||||
return None, is_package
|
return None, is_package
|
||||||
|
|
||||||
with module_file:
|
with module_file:
|
||||||
|
|||||||
@@ -63,7 +63,6 @@ only *inferes* what needs to be *inferred*. All the statements and modules
|
|||||||
that are not used are just being ignored.
|
that are not used are just being ignored.
|
||||||
"""
|
"""
|
||||||
import parso
|
import parso
|
||||||
from parso import python_bytes_to_unicode
|
|
||||||
from jedi.file_io import FileIO
|
from jedi.file_io import FileIO
|
||||||
|
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
@@ -186,7 +185,7 @@ class InferenceState(object):
|
|||||||
file_io = FileIO(path)
|
file_io = FileIO(path)
|
||||||
code = file_io.read()
|
code = file_io.read()
|
||||||
# We cannot just use parso, because it doesn't use errors='replace'.
|
# We cannot just use parso, because it doesn't use errors='replace'.
|
||||||
code = python_bytes_to_unicode(code, encoding=encoding, errors='replace')
|
code = parso.python_bytes_to_unicode(code, encoding=encoding, errors='replace')
|
||||||
|
|
||||||
if len(code) > settings._cropped_file_size:
|
if len(code) > settings._cropped_file_size:
|
||||||
code = code[:settings._cropped_file_size]
|
code = code[:settings._cropped_file_size]
|
||||||
|
|||||||
@@ -161,7 +161,9 @@ def unpack_arglist(arglist):
|
|||||||
if child == ',':
|
if child == ',':
|
||||||
continue
|
continue
|
||||||
elif child in ('*', '**'):
|
elif child in ('*', '**'):
|
||||||
yield len(child.value), next(iterator)
|
c = next(iterator, None)
|
||||||
|
assert c is not None
|
||||||
|
yield len(child.value), c
|
||||||
elif child.type == 'argument' and \
|
elif child.type == 'argument' and \
|
||||||
child.children[0] in ('*', '**'):
|
child.children[0] in ('*', '**'):
|
||||||
assert len(child.children) == 2
|
assert len(child.children) == 2
|
||||||
|
|||||||
@@ -70,8 +70,6 @@ class HelperValueMixin(object):
|
|||||||
yield f
|
yield f
|
||||||
|
|
||||||
def goto(self, name_or_str, name_context=None, analysis_errors=True):
|
def goto(self, name_or_str, name_context=None, analysis_errors=True):
|
||||||
if name_context is None:
|
|
||||||
name_context = self
|
|
||||||
from jedi.inference import finder
|
from jedi.inference import finder
|
||||||
filters = self._get_value_filters(name_or_str)
|
filters = self._get_value_filters(name_or_str)
|
||||||
names = finder.filter_name(filters, name_or_str)
|
names = finder.filter_name(filters, name_or_str)
|
||||||
@@ -218,7 +216,6 @@ class Value(HelperValueMixin, BaseValue):
|
|||||||
return ''
|
return ''
|
||||||
else:
|
else:
|
||||||
return clean_scope_docstring(self.tree_node)
|
return clean_scope_docstring(self.tree_node)
|
||||||
return None
|
|
||||||
|
|
||||||
def get_safe_value(self, default=sentinel):
|
def get_safe_value(self, default=sentinel):
|
||||||
if default is sentinel:
|
if default is sentinel:
|
||||||
|
|||||||
@@ -589,9 +589,6 @@ def _parse_function_doc(doc):
|
|||||||
|
|
||||||
def create_from_name(inference_state, compiled_value, name):
|
def create_from_name(inference_state, compiled_value, name):
|
||||||
access_paths = compiled_value.access_handle.getattr_paths(name, default=None)
|
access_paths = compiled_value.access_handle.getattr_paths(name, default=None)
|
||||||
parent_context = compiled_value
|
|
||||||
if parent_context.is_class():
|
|
||||||
parent_context = parent_context.parent_context
|
|
||||||
|
|
||||||
value = None
|
value = None
|
||||||
for access_path in access_paths:
|
for access_path in access_paths:
|
||||||
|
|||||||
@@ -220,8 +220,6 @@ def infer_return_types(function, arguments):
|
|||||||
function.get_default_param_context(),
|
function.get_default_param_context(),
|
||||||
match.group(1).strip()
|
match.group(1).strip()
|
||||||
).execute_annotation()
|
).execute_annotation()
|
||||||
if annotation is None:
|
|
||||||
return NO_VALUES
|
|
||||||
|
|
||||||
context = function.get_default_param_context()
|
context = function.get_default_param_context()
|
||||||
unknown_type_vars = find_unknown_type_vars(context, annotation)
|
unknown_type_vars = find_unknown_type_vars(context, annotation)
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class StubModuleValue(ModuleValue):
|
|||||||
|
|
||||||
def get_filters(self, origin_scope=None):
|
def get_filters(self, origin_scope=None):
|
||||||
filters = super(StubModuleValue, self).get_filters(origin_scope)
|
filters = super(StubModuleValue, self).get_filters(origin_scope)
|
||||||
next(filters) # Ignore the first filter and replace it with our own
|
next(filters, None) # Ignore the first filter and replace it with our own
|
||||||
stub_filters = self._get_stub_filters(origin_scope=origin_scope)
|
stub_filters = self._get_stub_filters(origin_scope=origin_scope)
|
||||||
for f in stub_filters:
|
for f in stub_filters:
|
||||||
yield f
|
yield f
|
||||||
@@ -76,7 +76,7 @@ class TypingModuleWrapper(StubModuleValue):
|
|||||||
class TypingModuleContext(ModuleContext):
|
class TypingModuleContext(ModuleContext):
|
||||||
def get_filters(self, *args, **kwargs):
|
def get_filters(self, *args, **kwargs):
|
||||||
filters = super(TypingModuleContext, self).get_filters(*args, **kwargs)
|
filters = super(TypingModuleContext, self).get_filters(*args, **kwargs)
|
||||||
yield TypingModuleFilterWrapper(next(filters))
|
yield TypingModuleFilterWrapper(next(filters, None))
|
||||||
for f in filters:
|
for f in filters:
|
||||||
yield f
|
yield f
|
||||||
|
|
||||||
|
|||||||
@@ -103,9 +103,6 @@ def import_module_decorator(func):
|
|||||||
# ``os.path``, because it's a very important one in Python
|
# ``os.path``, because it's a very important one in Python
|
||||||
# that is being achieved by messing with ``sys.modules`` in
|
# that is being achieved by messing with ``sys.modules`` in
|
||||||
# ``os``.
|
# ``os``.
|
||||||
python_parent = next(iter(parent_module_values))
|
|
||||||
if python_parent is None:
|
|
||||||
python_parent, = inference_state.import_module(('os',), prefer_stubs=False)
|
|
||||||
python_value_set = ValueSet.from_sets(
|
python_value_set = ValueSet.from_sets(
|
||||||
func(inference_state, (n,), None, sys_path,)
|
func(inference_state, (n,), None, sys_path,)
|
||||||
for n in [u'posixpath', u'ntpath', u'macpath', u'os2emxpath']
|
for n in [u'posixpath', u'ntpath', u'macpath', u'os2emxpath']
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ def _resolve_names(definition_names, avoid_names=()):
|
|||||||
yield name
|
yield name
|
||||||
|
|
||||||
if name.api_type == 'module':
|
if name.api_type == 'module':
|
||||||
for name in _resolve_names(name.goto(), definition_names):
|
for n in _resolve_names(name.goto(), definition_names):
|
||||||
yield name
|
yield n
|
||||||
|
|
||||||
|
|
||||||
def _dictionarize(names):
|
def _dictionarize(names):
|
||||||
|
|||||||
@@ -267,7 +267,6 @@ def get_parent_scope(node, include_flows=False):
|
|||||||
continue
|
continue
|
||||||
return scope
|
return scope
|
||||||
scope = scope.parent
|
scope = scope.parent
|
||||||
return scope
|
|
||||||
|
|
||||||
|
|
||||||
get_cached_parent_scope = _get_parent_scope_cache(get_parent_scope)
|
get_cached_parent_scope = _get_parent_scope_cache(get_parent_scope)
|
||||||
|
|||||||
Reference in New Issue
Block a user