Coverage for C:\Repos\ekr-pylint\pylint\message\message.py: 57%

42 statements  

« prev     ^ index     » next       coverage.py v6.4, created at 2022-05-24 10:21 -0500

1# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html 

2# For details: https://github.com/PyCQA/pylint/blob/main/LICENSE 

3# Copyright (c) https://github.com/PyCQA/pylint/blob/main/CONTRIBUTORS.txt 

4 

5from __future__ import annotations 

6 

7from dataclasses import asdict, dataclass 

8from warnings import warn 

9 

10from pylint.constants import MSG_TYPES 

11from pylint.interfaces import UNDEFINED, Confidence 

12from pylint.typing import MessageLocationTuple 

13 

14 

15@dataclass(unsafe_hash=True) 

16class Message: # pylint: disable=too-many-instance-attributes 

17 """This class represent a message to be issued by the reporters.""" 

18 

19 msg_id: str 

20 symbol: str 

21 msg: str 

22 C: str 

23 category: str 

24 confidence: Confidence 

25 abspath: str 

26 path: str 

27 module: str 

28 obj: str 

29 line: int 

30 column: int 

31 end_line: int | None 

32 end_column: int | None 

33 

34 def __init__( 

35 self, 

36 msg_id: str, 

37 symbol: str, 

38 location: tuple[str, str, str, str, int, int] | MessageLocationTuple, 

39 msg: str, 

40 confidence: Confidence | None, 

41 ) -> None: 

42 if not isinstance(location, MessageLocationTuple): 

43 warn( 

44 "In pylint 3.0, Messages will only accept a MessageLocationTuple as location parameter", 

45 DeprecationWarning, 

46 ) 

47 location = MessageLocationTuple( 

48 location[0], 

49 location[1], 

50 location[2], 

51 location[3], 

52 location[4], 

53 location[5], 

54 None, 

55 None, 

56 ) 

57 

58 self.msg_id = msg_id 

59 self.symbol = symbol 

60 self.msg = msg 

61 self.C = msg_id[0] 

62 self.category = MSG_TYPES[msg_id[0]] 

63 self.confidence = confidence or UNDEFINED 

64 self.abspath = location.abspath 

65 self.path = location.path 

66 self.module = location.module 

67 self.obj = location.obj 

68 self.line = location.line 

69 self.column = location.column 

70 self.end_line = location.end_line 

71 self.end_column = location.end_column 

72 

73 def format(self, template: str) -> str: 

74 """Format the message according to the given template. 

75 

76 The template format is the one of the format method : 

77 cf. https://docs.python.org/2/library/string.html#formatstrings 

78 """ 

79 return template.format(**asdict(self))