Skip to content

Remove unnecessary checks for node attributes in add_message #5622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions pylint/lint/pylinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,18 +1471,11 @@ def _add_one_message(
if node:
if not line:
line = node.fromlineno
# pylint: disable=fixme
# TODO: Initialize col_offset on every node (can be None) -> astroid
if not col_offset and hasattr(node, "col_offset"):
if not col_offset:
col_offset = node.col_offset
# pylint: disable=fixme
# TODO: Initialize end_lineno on every node (can be None) -> astroid
# See https://github.com/PyCQA/astroid/issues/1273
if not end_lineno and hasattr(node, "end_lineno"):
if not end_lineno:
end_lineno = node.end_lineno
# pylint: disable=fixme
# TODO: Initialize end_col_offset on every node (can be None) -> astroid
if not end_col_offset and hasattr(node, "end_col_offset"):
if not end_col_offset:
end_col_offset = node.end_col_offset

# should this message be displayed
Expand Down
23 changes: 12 additions & 11 deletions pylint/testutils/unittest_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ def add_message(
# If confidence is None we set it to UNDEFINED as well in PyLinter
if confidence is None:
confidence = UNDEFINED
if not line and node:
line = node.fromlineno
# pylint: disable=fixme
# TODO: Initialize col_offset, end_lineno and end_col_offset on every node -> astroid
# See https://github.com/PyCQA/astroid/issues/1273
if col_offset is None and node and hasattr(node, "col_offset"):
col_offset = node.col_offset
if not end_lineno and node and hasattr(node, "end_lineno"):
end_lineno = node.end_lineno
if not end_col_offset and node and hasattr(node, "end_col_offset"):
end_col_offset = node.end_col_offset

# Look up "location" data of node if not yet supplied
if node:
if not line:
line = node.fromlineno
if not col_offset:
col_offset = node.col_offset
if not end_lineno:
end_lineno = node.end_lineno
if not end_col_offset:
end_col_offset = node.end_col_offset

self._messages.append(
MessageTest(
msg_id,
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_min.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
-e .
# astroid dependency is also defined in setup.cfg
astroid==2.9.0 # Pinned to a specific version for tests
astroid==2.9.1 # Pinned to a specific version for tests
pytest~=6.2
pytest-benchmark~=3.4
gitpython>3
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ packages = find:
install_requires =
dill>=0.2
platformdirs>=2.2.0
astroid>=2.9.0,<2.10 # (You should also upgrade requirements_test_min.txt)
astroid>=2.9.1,<2.10 # (You should also upgrade requirements_test_min.txt)
isort>=4.2.5,<6
mccabe>=0.6,<0.7
toml>=0.9.2
Expand Down