diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2019-03-08 19:49:30 +0100 |
---|---|---|
committer | Claudiu Popa <pcmanticore@gmail.com> | 2019-03-09 11:09:29 +0100 |
commit | 2b5074986763d9a508a2dc38c99ba839612dc672 (patch) | |
tree | 56edfa83a3d3bc113e08a9e3f2dad274460a730d /pylint/message/message.py | |
parent | b1780d1a4f88d4a94c162780ef346ad66b44b172 (diff) | |
download | pylint-git-2b5074986763d9a508a2dc38c99ba839612dc672.tar.gz |
Refactor - Create a pylint.message package
There is a lot of Message related class in Utils
this warrant the creation of a new package.
See also review for burst utils.py into a package here:
https://github.com/PyCQA/pylint/pull/2654#issuecomment-470748956
Diffstat (limited to 'pylint/message/message.py')
-rw-r--r-- | pylint/message/message.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/pylint/message/message.py b/pylint/message/message.py new file mode 100644 index 000000000..f4a537600 --- /dev/null +++ b/pylint/message/message.py @@ -0,0 +1,53 @@ +# -*- coding: utf-8 -*- + +# Licensed under the GPL: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html +# For details: https://github.com/PyCQA/pylint/blob/master/COPYING + + +import collections + +from pylint.message.constants import MSG_TYPES + +_MsgBase = collections.namedtuple( + "_MsgBase", + [ + "msg_id", + "symbol", + "msg", + "C", + "category", + "confidence", + "abspath", + "path", + "module", + "obj", + "line", + "column", + ], +) + + +class Message(_MsgBase): + """This class represent a message to be issued by the reporters""" + + def __new__(cls, msg_id, symbol, location, msg, confidence): + return _MsgBase.__new__( + cls, + msg_id, + symbol, + msg, + msg_id[0], + MSG_TYPES[msg_id[0]], + confidence, + *location + ) + + def format(self, template): + """Format the message according to the given template. + + The template format is the one of the format method : + cf. http://docs.python.org/2/library/string.html#formatstrings + """ + # For some reason, _asdict on derived namedtuples does not work with + # Python 3.4. Needs some investigation. + return template.format(**dict(zip(self._fields, self))) |