Skip to content

Commit ef56e76

Browse files
authored
Remove unnecessary checks for node attributes in add_message (#5622)
1 parent e334af2 commit ef56e76

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

pylint/lint/pylinter.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,18 +1471,11 @@ def _add_one_message(
14711471
if node:
14721472
if not line:
14731473
line = node.fromlineno
1474-
# pylint: disable=fixme
1475-
# TODO: Initialize col_offset on every node (can be None) -> astroid
1476-
if not col_offset and hasattr(node, "col_offset"):
1474+
if not col_offset:
14771475
col_offset = node.col_offset
1478-
# pylint: disable=fixme
1479-
# TODO: Initialize end_lineno on every node (can be None) -> astroid
1480-
# See https://github.com/PyCQA/astroid/issues/1273
1481-
if not end_lineno and hasattr(node, "end_lineno"):
1476+
if not end_lineno:
14821477
end_lineno = node.end_lineno
1483-
# pylint: disable=fixme
1484-
# TODO: Initialize end_col_offset on every node (can be None) -> astroid
1485-
if not end_col_offset and hasattr(node, "end_col_offset"):
1478+
if not end_col_offset:
14861479
end_col_offset = node.end_col_offset
14871480

14881481
# should this message be displayed

pylint/testutils/unittest_linter.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,18 @@ def add_message(
4343
# If confidence is None we set it to UNDEFINED as well in PyLinter
4444
if confidence is None:
4545
confidence = UNDEFINED
46-
if not line and node:
47-
line = node.fromlineno
48-
# pylint: disable=fixme
49-
# TODO: Initialize col_offset, end_lineno and end_col_offset on every node -> astroid
50-
# See https://github.com/PyCQA/astroid/issues/1273
51-
if col_offset is None and node and hasattr(node, "col_offset"):
52-
col_offset = node.col_offset
53-
if not end_lineno and node and hasattr(node, "end_lineno"):
54-
end_lineno = node.end_lineno
55-
if not end_col_offset and node and hasattr(node, "end_col_offset"):
56-
end_col_offset = node.end_col_offset
46+
47+
# Look up "location" data of node if not yet supplied
48+
if node:
49+
if not line:
50+
line = node.fromlineno
51+
if not col_offset:
52+
col_offset = node.col_offset
53+
if not end_lineno:
54+
end_lineno = node.end_lineno
55+
if not end_col_offset:
56+
end_col_offset = node.end_col_offset
57+
5758
self._messages.append(
5859
MessageTest(
5960
msg_id,

0 commit comments

Comments
 (0)