From b1f27e211908f1dbaefbe47670d41fd5d5c5e534 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 31 Dec 2021 14:14:44 +0100 Subject: [PATCH] Remove unnecessary checks for node attributes in ``add_message`` --- pylint/lint/pylinter.py | 13 +++---------- pylint/testutils/unittest_linter.py | 23 ++++++++++++----------- requirements_test_min.txt | 2 +- setup.cfg | 2 +- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/pylint/lint/pylinter.py b/pylint/lint/pylinter.py index 1d6b5a3b1a..49ddb29ad9 100644 --- a/pylint/lint/pylinter.py +++ b/pylint/lint/pylinter.py @@ -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 diff --git a/pylint/testutils/unittest_linter.py b/pylint/testutils/unittest_linter.py index 0c45264f7b..c9945f52fb 100644 --- a/pylint/testutils/unittest_linter.py +++ b/pylint/testutils/unittest_linter.py @@ -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, diff --git a/requirements_test_min.txt b/requirements_test_min.txt index a0e339897d..955b6683e9 100644 --- a/requirements_test_min.txt +++ b/requirements_test_min.txt @@ -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 diff --git a/setup.cfg b/setup.cfg index 8b438e6459..1d1a8cc723 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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