@@ -1413,14 +1413,30 @@ def _add_one_message(
1413
1413
args : Optional [Any ],
1414
1414
confidence : Optional [interfaces .Confidence ],
1415
1415
col_offset : Optional [int ],
1416
+ end_lineno : Optional [int ],
1417
+ end_col_offset : Optional [int ],
1416
1418
) -> None :
1417
1419
"""After various checks have passed a single Message is
1418
1420
passed to the reporter and added to stats"""
1419
1421
message_definition .check_message_definition (line , node )
1420
- if line is None and node is not None :
1421
- line = node .fromlineno
1422
- if col_offset is None and hasattr (node , "col_offset" ):
1423
- col_offset = node .col_offset # type: ignore[union-attr]
1422
+
1423
+ # Look up "location" data of node if not yet supplied
1424
+ if node :
1425
+ if not line :
1426
+ line = node .fromlineno
1427
+ # pylint: disable=fixme
1428
+ # TODO: Initialize col_offset on every node (can be None) -> astroid
1429
+ if not col_offset and hasattr (node , "col_offset" ):
1430
+ col_offset = node .col_offset
1431
+ # pylint: disable=fixme
1432
+ # TODO: Initialize end_lineno on every node (can be None) -> astroid
1433
+ # See https://github.com/PyCQA/astroid/issues/1273
1434
+ if not end_lineno and hasattr (node , "end_lineno" ):
1435
+ end_lineno = node .end_lineno
1436
+ # pylint: disable=fixme
1437
+ # TODO: Initialize end_col_offset on every node (can be None) -> astroid
1438
+ if not end_col_offset and hasattr (node , "end_col_offset" ):
1439
+ end_col_offset = node .end_col_offset
1424
1440
1425
1441
# should this message be displayed
1426
1442
if not self .is_message_enabled (message_definition .msgid , line , confidence ):
@@ -1463,7 +1479,14 @@ def _add_one_message(
1463
1479
message_definition .msgid ,
1464
1480
message_definition .symbol ,
1465
1481
MessageLocationTuple (
1466
- abspath , path , module or "" , obj , line or 1 , col_offset or 0
1482
+ abspath ,
1483
+ path ,
1484
+ module or "" ,
1485
+ obj ,
1486
+ line or 1 ,
1487
+ col_offset or 0 ,
1488
+ end_lineno ,
1489
+ end_col_offset ,
1467
1490
),
1468
1491
msg ,
1469
1492
confidence ,
@@ -1478,6 +1501,8 @@ def add_message(
1478
1501
args : Optional [Any ] = None ,
1479
1502
confidence : Optional [interfaces .Confidence ] = None ,
1480
1503
col_offset : Optional [int ] = None ,
1504
+ end_lineno : Optional [int ] = None ,
1505
+ end_col_offset : Optional [int ] = None ,
1481
1506
) -> None :
1482
1507
"""Adds a message given by ID or name.
1483
1508
@@ -1492,7 +1517,14 @@ def add_message(
1492
1517
message_definitions = self .msgs_store .get_message_definitions (msgid )
1493
1518
for message_definition in message_definitions :
1494
1519
self ._add_one_message (
1495
- message_definition , line , node , args , confidence , col_offset
1520
+ message_definition ,
1521
+ line ,
1522
+ node ,
1523
+ args ,
1524
+ confidence ,
1525
+ col_offset ,
1526
+ end_lineno ,
1527
+ end_col_offset ,
1496
1528
)
1497
1529
1498
1530
def add_ignored_message (
0 commit comments