Skip to content
Snippets Groups Projects
Commit c790341f authored by Claudiu Popa's avatar Claudiu Popa
Browse files

Wip stages

parent 6bc5d82d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -31,15 +31,20 @@ _MsgBase = collections.namedtuple(
'abspath', 'path', 'module', 'obj', 'line', 'column'])
_MessageOptions = collections.namedtuple(
'_MessageOptions',
['minversion', 'maxversion', 'old_names', 'scope']
['minversion', 'maxversion', 'old_names', 'scope', 'stage']
)
 
class MessageOptions(_MessageOptions):
"""Holds options for a particular message."""
 
def __new__(cls, minversion=None, maxversion=None, old_names=None, scope=None):
def __new__(cls, minversion=None, maxversion=None,
old_names=None, scope=None, stage=None):
return _MessageOptions.__new__(
cls, minversion, maxversion, old_names, scope)
cls, minversion=minversion,
maxversion=maxversion,
old_names=old_names,
scope=scope,
stage=stage)
 
 
class Message(_MsgBase):
Loading
Loading
@@ -74,6 +79,7 @@ class MessageDefinition(object):
self.minversion = options.minversion
self.maxversion = options.maxversion
self.old_names = options.old_names or []
self.stage = options.stage
 
def may_be_emitted(self):
"""return True if message may be emitted using the current interpreter"""
Loading
Loading
@@ -189,6 +195,11 @@ class MessagesStore(object):
self._alternative_names[old_symbol] = msg
self._msgs_by_category[msg.msgid[0]].append(msg.msgid)
 
def stage_messages(self, stage):
"""Select all the messages for the given stage."""
return [message for message in self._messages.values()
if message.stage == stage]
def check_message_id(self, msgid):
"""returns the Message object for this message.
 
Loading
Loading
# 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 enum
_Stage = enum.Enum('Stage', 'CORE PEDANTIC REFACTORING STYLE ADDITIONAL')
# pylint: disable=no-member; github.com/pycqa/pylint/issues/690
CORE = _Stage.CORE
PEDANTIC = _Stage.PEDANTIC
REFACTORING = _Stage.REFACTORING
STYLE = _Stage.STYLE
ADDITIONAL = _Stage.ADDITIONAL
del _Stage
def next_stage(stage_step):
"""Get the next stage from the given one or None, if there is no next one."""
stages = list(type(stage_step))
try:
index = stages.index(stage_step)
return stages[index + 1]
except (IndexError, ValueError):
# We are at the end of the stages or th stage step was
# too big.
return None
\ No newline at end of file
Loading
Loading
@@ -35,6 +35,7 @@ from pylint.reporters import text, html
from pylint import checkers
from pylint.checkers.utils import check_messages
from pylint import interfaces
from pylint import stage
 
if os.name == 'java':
if os._name == 'nt':
Loading
Loading
@@ -613,7 +614,7 @@ class PreprocessOptionsTC(unittest.TestCase):
{'bar' : (None, False)})
 
 
class MessagesStoreTC(unittest.TestCase):
class MessagesStoreTest(unittest.TestCase):
def setUp(self):
self.store = MessagesStore()
class Checker(object):
Loading
Loading
@@ -686,6 +687,30 @@ class MessagesStoreTC(unittest.TestCase):
self.assertEqual('msg-symbol',
self.store.check_message_id('old-symbol').symbol)
 
def test_stage_messages(self):
store = MessagesStore()
class Checker(object):
name = 'achecker'
msgs = {
'W1234': ('message', 'msg-symbol', 'msg description.',
{'old_names': [('W0001', 'old-symbol')], 'stage': stage.CORE}),
'W1235': ('message', 'msg-symbol-1', 'msg description.',
{'old_names': [('W0001', 'old-symbol')], 'stage': stage.CORE}),
'E1234': ('Duplicate keyword argument %r in %s call',
'duplicate-keyword-arg',
'Used when a function call passes the same keyword argument multiple times.',
{'maxversion': (2, 6), 'stage': stage.PEDANTIC}),
}
store.register_messages(Checker())
core = store.stage_messages(stage.CORE)
self.assertEqual(len(core), 2)
self.assertEqual([msg.symbol for msg in core], ['msg-symbol', 'msg-symbol-1'])
pedantic = store.stage_messages(stage.PEDANTIC)
self.assertEqual(len(pedantic), 1)
self.assertEqual(pedantic[0].symbol, 'duplicate-keyword-arg')
 
class MessageDefinitionTest(unittest.TestCase):
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment