Skip to content

Commit

Permalink
Fix a regression where messages with dash are not fully parsed
Browse files Browse the repository at this point in the history
Close #3604
  • Loading branch information
PCManticore committed May 14, 2020
1 parent 62edb58 commit 5cbdd94
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Release date: TBA

Close #3612

* Fix a regression where messages with dash are not fully parsed

Close #3604


What's New in Pylint 2.5.2?
===========================
Expand Down
4 changes: 2 additions & 2 deletions pylint/utils/pragma_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
.*? # Anything (as little as possible)
\bpylint: # pylint word and column
\s* # Any number of whitespaces
([^;#\n]+)) # Anything except semicolon or hash or newline (it is the second matched group)
([^;#\n]+)) # Anything except semicolon or hash or newline (it is the second matched group)
# and end of the first matched group
[;#]{0,1}""" # From 0 to 1 repetition of semicolon or hash
OPTION_PO = re.compile(OPTION_RGX, re.VERBOSE)
Expand All @@ -39,7 +39,7 @@

TOKEN_SPECIFICATION = [
("KEYWORD", r"\b({:s})\b".format(ALL_KEYWORDS)),
("MESSAGE_STRING", r"[A-Za-z\-]{2,}"), #  Identifiers
("MESSAGE_STRING", r"[A-Za-z\-\_]{2,}"), #  Identifiers
("ASSIGN", r"="), #  Assignment operator
("MESSAGE_NUMBER", r"[CREIWF]{1}\d*"),
]
Expand Down
8 changes: 8 additions & 0 deletions tests/test_pragma_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ def test_missing_message():
match = OPTION_PO.search(comment)
with pytest.raises(InvalidPragmaError):
list(parse_pragma(match.group(2)))


def test_parse_message_with_dash():
comment = "#pylint: disable = raw_input-builtin"
match = OPTION_PO.search(comment)
res = list(parse_pragma(match.group(2)))
assert res[0].action == "disable"
assert res[0].messages == ["raw_input-builtin"]

0 comments on commit 5cbdd94

Please sign in to comment.