@@ -1219,6 +1219,7 @@ def _report_evaluation(self, verbose: bool = False) -> int | None:
12191219 self .reporter .display_reports (sect )
12201220 return note
12211221
1222+ # pylint: disable-next=too-many-arguments
12221223 def _add_one_message (
12231224 self ,
12241225 message_definition : MessageDefinition ,
@@ -1229,6 +1230,8 @@ def _add_one_message(
12291230 col_offset : int | None ,
12301231 end_lineno : int | None ,
12311232 end_col_offset : int | None ,
1233+ module : str | None = None ,
1234+ filepath : str | None = None ,
12321235 ) -> None :
12331236 """After various checks have passed a single Message is
12341237 passed to the reporter and added to stats.
@@ -1282,11 +1285,15 @@ def _add_one_message(
12821285 msg %= args
12831286 # get module and object
12841287 if node is None :
1285- module , obj = self .current_name , ""
1288+ _module , obj = self .current_name , ""
12861289 abspath = self .current_file
12871290 else :
1288- module , obj = utils .get_module_and_frameid (node )
1291+ _module , obj = utils .get_module_and_frameid (node )
12891292 abspath = node .root ().file
1293+ if module is not None :
1294+ _module = module
1295+ if filepath is not None :
1296+ abspath = filepath
12901297 if abspath is not None :
12911298 path = abspath .replace (self .reporter .path_strip_prefix , "" , 1 )
12921299 else :
@@ -1299,7 +1306,7 @@ def _add_one_message(
12991306 MessageLocationTuple (
13001307 abspath or "" ,
13011308 path ,
1302- module or "" ,
1309+ _module or "" ,
13031310 obj ,
13041311 line or 1 ,
13051312 col_offset or 0 ,
@@ -1311,6 +1318,7 @@ def _add_one_message(
13111318 )
13121319 )
13131320
1321+ # pylint: disable-next=too-many-arguments
13141322 def add_message (
13151323 self ,
13161324 msgid : str ,
@@ -1321,6 +1329,8 @@ def add_message(
13211329 col_offset : int | None = None ,
13221330 end_lineno : int | None = None ,
13231331 end_col_offset : int | None = None ,
1332+ module : str | None = None ,
1333+ filepath : str | None = None ,
13241334 ) -> None :
13251335 """Adds a message given by ID or name.
13261336
@@ -1329,6 +1339,9 @@ def add_message(
13291339 AST checkers must provide the node argument (but may optionally
13301340 provide line if the line number is different), raw and token checkers
13311341 must provide the line argument.
1342+
1343+ The module and filepath parameters allow overriding the module name
1344+ and file path reported in the message location.
13321345 """
13331346 if confidence is None :
13341347 confidence = interfaces .UNDEFINED
@@ -1343,6 +1356,8 @@ def add_message(
13431356 col_offset ,
13441357 end_lineno ,
13451358 end_col_offset ,
1359+ module = module ,
1360+ filepath = filepath ,
13461361 )
13471362
13481363 def add_ignored_message (
0 commit comments