Some more code quality fixes

This commit is contained in:
Dave Halter
2020-04-11 02:23:23 +02:00
parent bdd4deedc1
commit 02c3d651bd
11 changed files with 10 additions and 22 deletions

View File

@@ -27,8 +27,8 @@ def _start_linter():
paths = [path]
try:
for path in paths:
for error in jedi.Script(path=path)._analysis():
for p in paths:
for error in jedi.Script(path=p)._analysis():
print(error)
except Exception:
if '--pdb' in sys.argv:

View File

@@ -186,7 +186,6 @@ def find_module_pre_py3(string, path=None, full_name=None, is_global_search=True
module_file = None
if module_file is None:
code = None
return None, is_package
with module_file:

View 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.
"""
import parso
from parso import python_bytes_to_unicode
from jedi.file_io import FileIO
from jedi import debug
@@ -186,7 +185,7 @@ class InferenceState(object):
file_io = FileIO(path)
code = file_io.read()
# 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:
code = code[:settings._cropped_file_size]

View File

@@ -161,7 +161,9 @@ def unpack_arglist(arglist):
if child == ',':
continue
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 \
child.children[0] in ('*', '**'):
assert len(child.children) == 2

View File

@@ -70,8 +70,6 @@ class HelperValueMixin(object):
yield f
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
filters = self._get_value_filters(name_or_str)
names = finder.filter_name(filters, name_or_str)
@@ -218,7 +216,6 @@ class Value(HelperValueMixin, BaseValue):
return ''
else:
return clean_scope_docstring(self.tree_node)
return None
def get_safe_value(self, default=sentinel):
if default is sentinel:

View File

@@ -589,9 +589,6 @@ def _parse_function_doc(doc):
def create_from_name(inference_state, compiled_value, name):
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
for access_path in access_paths:

View File

@@ -220,8 +220,6 @@ def infer_return_types(function, arguments):
function.get_default_param_context(),
match.group(1).strip()
).execute_annotation()
if annotation is None:
return NO_VALUES
context = function.get_default_param_context()
unknown_type_vars = find_unknown_type_vars(context, annotation)

View File

@@ -41,7 +41,7 @@ class StubModuleValue(ModuleValue):
def get_filters(self, origin_scope=None):
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)
for f in stub_filters:
yield f
@@ -76,7 +76,7 @@ class TypingModuleWrapper(StubModuleValue):
class TypingModuleContext(ModuleContext):
def get_filters(self, *args, **kwargs):
filters = super(TypingModuleContext, self).get_filters(*args, **kwargs)
yield TypingModuleFilterWrapper(next(filters))
yield TypingModuleFilterWrapper(next(filters, None))
for f in filters:
yield f

View File

@@ -103,9 +103,6 @@ def import_module_decorator(func):
# ``os.path``, because it's a very important one in Python
# that is being achieved by messing with ``sys.modules`` in
# ``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(
func(inference_state, (n,), None, sys_path,)
for n in [u'posixpath', u'ntpath', u'macpath', u'os2emxpath']

View File

@@ -38,8 +38,8 @@ def _resolve_names(definition_names, avoid_names=()):
yield name
if name.api_type == 'module':
for name in _resolve_names(name.goto(), definition_names):
yield name
for n in _resolve_names(name.goto(), definition_names):
yield n
def _dictionarize(names):

View File

@@ -267,7 +267,6 @@ def get_parent_scope(node, include_flows=False):
continue
return scope
scope = scope.parent
return scope
get_cached_parent_scope = _get_parent_scope_cache(get_parent_scope)