Skip to content

Commit 5cbdd94

Browse files
committed
Fix a regression where messages with dash are not fully parsed
Close #3604
1 parent 62edb58 commit 5cbdd94

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Release date: TBA
1515

1616
Close #3612
1717

18+
* Fix a regression where messages with dash are not fully parsed
19+
20+
Close #3604
21+
1822

1923
What's New in Pylint 2.5.2?
2024
===========================

pylint/utils/pragma_parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
.*? # Anything (as little as possible)
1818
\bpylint: # pylint word and column
1919
\s* # Any number of whitespaces
20-
([^;#\n]+)) # Anything except semicolon or hash or newline (it is the second matched group)
20+
([^;#\n]+)) # Anything except semicolon or hash or newline (it is the second matched group)
2121
# and end of the first matched group
2222
[;#]{0,1}""" # From 0 to 1 repetition of semicolon or hash
2323
OPTION_PO = re.compile(OPTION_RGX, re.VERBOSE)
@@ -39,7 +39,7 @@
3939

4040
TOKEN_SPECIFICATION = [
4141
("KEYWORD", r"\b({:s})\b".format(ALL_KEYWORDS)),
42-
("MESSAGE_STRING", r"[A-Za-z\-]{2,}"), #  Identifiers
42+
("MESSAGE_STRING", r"[A-Za-z\-\_]{2,}"), #  Identifiers
4343
("ASSIGN", r"="), #  Assignment operator
4444
("MESSAGE_NUMBER", r"[CREIWF]{1}\d*"),
4545
]

tests/test_pragma_parser.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,11 @@ def test_missing_message():
8282
match = OPTION_PO.search(comment)
8383
with pytest.raises(InvalidPragmaError):
8484
list(parse_pragma(match.group(2)))
85+
86+
87+
def test_parse_message_with_dash():
88+
comment = "#pylint: disable = raw_input-builtin"
89+
match = OPTION_PO.search(comment)
90+
res = list(parse_pragma(match.group(2)))
91+
assert res[0].action == "disable"
92+
assert res[0].messages == ["raw_input-builtin"]

0 commit comments

Comments
 (0)