Skip to content

Commit

Permalink
Merge 061efa3 into dc83a86
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd authored Dec 23, 2019
2 parents dc83a86 + 061efa3 commit e7ce1ba
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 59 deletions.
13 changes: 6 additions & 7 deletions pylint/checkers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1885,13 +1885,12 @@ def visit_assignname(self, node):
if isinstance(assign_type, astroid.Assign) and not in_loop(assign_type):
if isinstance(utils.safe_infer(assign_type.value), astroid.ClassDef):
self._check_name("class", node.name, node)
else:
# Don't emit if the name redefines an import
# in an ImportError except handler.
if not _redefines_import(node) and isinstance(
utils.safe_infer(assign_type.value), astroid.Const
):
self._check_name("const", node.name, node)
# Don't emit if the name redefines an import
# in an ImportError except handler.
elif not _redefines_import(node) and isinstance(
utils.safe_infer(assign_type.value), astroid.Const
):
self._check_name("const", node.name, node)
elif isinstance(assign_type, astroid.ExceptHandler):
self._check_name("variable", node.name, node)
elif isinstance(frame, astroid.FunctionDef):
Expand Down
2 changes: 1 addition & 1 deletion pylint/checkers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ def _check_first_arg_for_type(self, node, metaclass=0):
node.name,
)
# regular class
else:
else: # pylint: disable=else-if-used
# class method
if node.type == "classmethod" or node.name == "__class_getitem__":
self._check_first_arg_config(
Expand Down
22 changes: 10 additions & 12 deletions pylint/checkers/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,18 +1176,16 @@ def visit_default(self, node):
prev_sibl = node.previous_sibling()
if prev_sibl is not None:
prev_line = prev_sibl.fromlineno
# The line on which a finally: occurs in a try/finally
# is not directly represented in the AST. We infer it
# by taking the last line of the body and adding 1, which
# should be the line of finally:
elif (
isinstance(node.parent, nodes.TryFinally) and node in node.parent.finalbody
):
prev_line = node.parent.body[0].tolineno + 1
else:
# The line on which a finally: occurs in a try/finally
# is not directly represented in the AST. We infer it
# by taking the last line of the body and adding 1, which
# should be the line of finally:
if (
isinstance(node.parent, nodes.TryFinally)
and node in node.parent.finalbody
):
prev_line = node.parent.body[0].tolineno + 1
else:
prev_line = node.parent.statement().fromlineno
prev_line = node.parent.statement().fromlineno
line = node.fromlineno
assert line, node
if prev_line == line and self._visited_lines.get(line) != 2:
Expand Down Expand Up @@ -1275,7 +1273,7 @@ def check_line_length(self, line: str, i: int) -> None:
@staticmethod
def remove_pylint_option_from_lines(options_pattern_obj) -> str:
"""
Remove the `# pylint ...` pattern from lines
Remove the `# pylint ...` pattern from lines
"""
lines = options_pattern_obj.string
purged_lines = (
Expand Down
9 changes: 4 additions & 5 deletions pylint/checkers/python3.py
Original file line number Diff line number Diff line change
Expand Up @@ -1212,11 +1212,10 @@ def visit_call(self, node):
return
if node.func.attrname == "next":
self.add_message("next-method-called", node=node)
else:
if node.func.attrname in ("iterkeys", "itervalues", "iteritems"):
self.add_message("dict-iter-method", node=node)
elif node.func.attrname in ("viewkeys", "viewvalues", "viewitems"):
self.add_message("dict-view-method", node=node)
elif node.func.attrname in ("iterkeys", "itervalues", "iteritems"):
self.add_message("dict-iter-method", node=node)
elif node.func.attrname in ("viewkeys", "viewvalues", "viewitems"):
self.add_message("dict-view-method", node=node)
elif isinstance(node.func, astroid.Name):
found_node = node.func.lookup(node.func.name)[0]
if _is_builtin(found_node):
Expand Down
24 changes: 11 additions & 13 deletions pylint/checkers/typecheck.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,11 @@ def _no_context_variadic_keywords(node, scope):

if isinstance(scope, astroid.Lambda) and not isinstance(scope, astroid.FunctionDef):
variadics = list(node.keywords or []) + node.kwargs
else:
if isinstance(statement, (astroid.Return, astroid.Expr)) and isinstance(
statement.value, astroid.Call
):
call = statement.value
variadics = list(call.keywords or []) + call.kwargs
elif isinstance(statement, (astroid.Return, astroid.Expr)) and isinstance(
statement.value, astroid.Call
):
call = statement.value
variadics = list(call.keywords or []) + call.kwargs

return _no_context_variadic(node, scope.args.kwarg, astroid.Keyword, variadics)

Expand Down Expand Up @@ -1296,13 +1295,12 @@ def visit_call(self, node):
# The remaining positional arguments get assigned to the *args
# parameter.
break
else:
if not overload_function:
# Too many positional arguments.
self.add_message(
"too-many-function-args", node=node, args=(callable_name,)
)
break
elif not overload_function:
# Too many positional arguments.
self.add_message(
"too-many-function-args", node=node, args=(callable_name,)
)
break

# 2. Match the keyword arguments.
for keyword in keyword_args:
Expand Down
26 changes: 12 additions & 14 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,13 +1290,12 @@ def _is_variable_violation(
use_outer_definition = stmt == defstmt and not isinstance(
defnode, astroid.node_classes.Comprehension
)
else:
# check if we have a nonlocal
if name in defframe.locals:
maybee0601 = not any(
isinstance(child, astroid.Nonlocal) and name in child.names
for child in defframe.get_children()
)
# check if we have a nonlocal
elif name in defframe.locals:
maybee0601 = not any(
isinstance(child, astroid.Nonlocal) and name in child.names
for child in defframe.get_children()
)

if (
base_scope_type == "lambda"
Expand Down Expand Up @@ -1780,13 +1779,12 @@ def _check_unpacking(self, inferred, node, targets):
),
)
# attempt to check unpacking may be possible (ie RHS is iterable)
else:
if not utils.is_iterable(inferred):
self.add_message(
"unpacking-non-sequence",
node=node,
args=(_get_unpacking_extra_info(node, inferred),),
)
elif not utils.is_iterable(inferred):
self.add_message(
"unpacking-non-sequence",
node=node,
args=(_get_unpacking_extra_info(node, inferred),),
)

def _check_module_attrs(self, node, module, module_names):
"""check that module_names (list of string) are accessible through the
Expand Down
12 changes: 5 additions & 7 deletions pylint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ def _merge_stats(stats):
for key, item in stat.items():
if key not in merged:
merged[key] = item
elif isinstance(item, dict):
merged[key].update(item)
else:
if isinstance(item, dict):
merged[key].update(item)
else:
merged[key] = merged[key] + item
merged[key] = merged[key] + item

merged["by_msg"] = by_msg
return merged
Expand Down Expand Up @@ -1757,9 +1756,8 @@ def __init__(self, args, reporter=None, do_exit=True):
file=sys.stderr,
)
linter.set_option("jobs", 1)
else:
if linter.config.jobs == 0:
linter.config.jobs = _cpu_count()
elif linter.config.jobs == 0:
linter.config.jobs = _cpu_count()

# We have loaded configuration from config file and command line. Now, we can
# load plugin specific configuration.
Expand Down
1 change: 1 addition & 0 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ persistent=yes
# List of plugins (as comma separated values of python modules names) to load,
# usually to register additional checkers.
load-plugins=
pylint.extensions.check_elif

# Use multiple processes to speed up Pylint.
jobs=1
Expand Down

0 comments on commit e7ce1ba

Please sign in to comment.