Skip to content

Commit 9ecc4ef

Browse files
Capitalize syntax error in type comment messages (#15236)
Fixes #15132
1 parent ffdaee9 commit 9ecc4ef

File tree

6 files changed

+29
-29
lines changed

6 files changed

+29
-29
lines changed

mypy/message_registry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def with_additional_msg(self, info: str) -> ErrorMessage:
289289
)
290290
INVALID_TYPE_IGNORE: Final = ErrorMessage('Invalid "type: ignore" comment', codes.SYNTAX)
291291
TYPE_COMMENT_SYNTAX_ERROR_VALUE: Final = ErrorMessage(
292-
'syntax error in type comment "{}"', codes.SYNTAX
292+
'Syntax error in type comment "{}"', codes.SYNTAX
293293
)
294294
ELLIPSIS_WITH_OTHER_TYPEARGS: Final = ErrorMessage(
295295
"Ellipses cannot accompany other argument types in function type signature", codes.SYNTAX

test-data/unit/check-columns.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ if int():
328328
# TODO: It would be better to point to the type comment
329329
xyz = 0 # type: blurbnard blarb
330330
[out]
331-
main:3:5: error: syntax error in type comment "blurbnard blarb"
331+
main:3:5: error: Syntax error in type comment "blurbnard blarb"
332332

333333
[case testColumnProperty]
334334
class A:

test-data/unit/check-errorcodes.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def f(): # E: Type signature has too many arguments [syntax]
4242
# type: (int) -> None
4343
1
4444

45-
x = 0 # type: x y # E: syntax error in type comment "x y" [syntax]
45+
x = 0 # type: x y # E: Syntax error in type comment "x y" [syntax]
4646

4747
[case testErrorCodeSyntaxError3]
4848
# This is a bit inconsistent -- syntax error would be more logical?
@@ -720,8 +720,8 @@ main:2: error: Name "y" is not defined [name-defined]
720720
x = y # type: int # type: ignored[foo]
721721
x = y # type: int # type: ignored [foo]
722722
[out]
723-
main:1: error: syntax error in type comment "int" [syntax]
724-
main:2: error: syntax error in type comment "int" [syntax]
723+
main:1: error: Syntax error in type comment "int" [syntax]
724+
main:2: error: Syntax error in type comment "int" [syntax]
725725

726726
[case testErrorCode__exit__Return]
727727
class InvalidReturn:

test-data/unit/check-fastparse.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
[case testFastParseTypeCommentSyntaxError]
66

7-
x = None # type: a : b # E: syntax error in type comment "a : b"
7+
x = None # type: a : b # E: Syntax error in type comment "a : b"
88

99
[case testFastParseInvalidTypeComment]
1010

@@ -14,13 +14,13 @@ x = None # type: a + b # E: Invalid type comment or annotation
1414
-- This happens in both parsers.
1515
[case testFastParseFunctionAnnotationSyntaxError]
1616

17-
def f(): # E: syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses
17+
def f(): # E: Syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses
1818
# type: None -> None
1919
pass
2020

2121
[case testFastParseFunctionAnnotationSyntaxErrorSpaces]
2222

23-
def f(): # E: syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses
23+
def f(): # E: Syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses
2424
# type: None -> None
2525
pass
2626

test-data/unit/check-literal.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ reveal_type(g2) # N: Revealed type is "def (x: Literal['A B'])"
1919

2020
[case testLiteralInvalidTypeComment]
2121
from typing_extensions import Literal
22-
def f(x): # E: syntax error in type comment "(A[) -> None"
22+
def f(x): # E: Syntax error in type comment "(A[) -> None"
2323
# type: (A[) -> None
2424
pass
2525

test-data/unit/parse-errors.test

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,116 +113,116 @@ file:1: error: invalid syntax
113113
0
114114
x = 0 # type: A A
115115
[out]
116-
file:2: error: syntax error in type comment "A A"
116+
file:2: error: Syntax error in type comment "A A"
117117

118118
[case testInvalidTypeComment2]
119119
0
120120
x = 0 # type: A[
121121
[out]
122-
file:2: error: syntax error in type comment "A["
122+
file:2: error: Syntax error in type comment "A["
123123

124124
[case testInvalidTypeComment3]
125125
0
126126
x = 0 # type:
127127
[out]
128-
file:2: error: syntax error in type comment ""
128+
file:2: error: Syntax error in type comment ""
129129

130130
[case testInvalidTypeComment4]
131131
0
132132
x = 0 # type: *
133133
[out]
134-
file:2: error: syntax error in type comment "*"
134+
file:2: error: Syntax error in type comment "*"
135135

136136
[case testInvalidTypeComment5]
137137
0
138138
x = 0 # type:# some comment
139139
[out]
140-
file:2: error: syntax error in type comment ""
140+
file:2: error: Syntax error in type comment ""
141141

142142
[case testInvalidTypeComment6]
143143
0
144144
x = 0 # type: *# comment #6
145145
[out]
146-
file:2: error: syntax error in type comment "*"
146+
file:2: error: Syntax error in type comment "*"
147147

148148
[case testInvalidTypeComment7]
149149
0
150150
x = 0 # type: A B #comment #7
151151
[out]
152-
file:2: error: syntax error in type comment "A B"
152+
file:2: error: Syntax error in type comment "A B"
153153

154154
[case testInvalidSignatureInComment1]
155155
def f(): # type: x
156156
pass
157157
[out]
158-
file:1: error: syntax error in type comment "x"
158+
file:1: error: Syntax error in type comment "x"
159159
file:1: note: Suggestion: wrap argument types in parentheses
160160

161161
[case testInvalidSignatureInComment2]
162162
def f(): # type:
163163
pass
164164
[out]
165-
file:1: error: syntax error in type comment ""
165+
file:1: error: Syntax error in type comment ""
166166

167167
[case testInvalidSignatureInComment3]
168168
def f(): # type: (
169169
pass
170170
[out]
171-
file:1: error: syntax error in type comment "("
171+
file:1: error: Syntax error in type comment "("
172172

173173
[case testInvalidSignatureInComment4]
174174
def f(): # type: (.
175175
pass
176176
[out]
177-
file:1: error: syntax error in type comment "(."
177+
file:1: error: Syntax error in type comment "(."
178178

179179
[case testInvalidSignatureInComment5]
180180
def f(): # type: (x
181181
pass
182182
[out]
183-
file:1: error: syntax error in type comment "(x"
183+
file:1: error: Syntax error in type comment "(x"
184184

185185
[case testInvalidSignatureInComment6]
186186
def f(): # type: (x)
187187
pass
188188
[out]
189-
file:1: error: syntax error in type comment "(x)"
189+
file:1: error: Syntax error in type comment "(x)"
190190

191191
[case testInvalidSignatureInComment7]
192192
def f(): # type: (x) -
193193
pass
194194
[out]
195-
file:1: error: syntax error in type comment "(x) -"
195+
file:1: error: Syntax error in type comment "(x) -"
196196

197197
[case testInvalidSignatureInComment8]
198198
def f(): # type: (x) ->
199199
pass
200200
[out]
201-
file:1: error: syntax error in type comment "(x) ->"
201+
file:1: error: Syntax error in type comment "(x) ->"
202202

203203
[case testInvalidSignatureInComment9]
204204
def f(): # type: (x) -> .
205205
pass
206206
[out]
207-
file:1: error: syntax error in type comment "(x) -> ."
207+
file:1: error: Syntax error in type comment "(x) -> ."
208208

209209
[case testInvalidSignatureInComment10]
210210
def f(): # type: (x) -> x x
211211
pass
212212
[out]
213-
file:1: error: syntax error in type comment "(x) -> x x"
213+
file:1: error: Syntax error in type comment "(x) -> x x"
214214

215215
[case testInvalidSignatureInComment11]
216216
def f(): # type: # abc comment
217217
pass
218218
[out]
219-
file:1: error: syntax error in type comment ""
219+
file:1: error: Syntax error in type comment ""
220220

221221
[case testInvalidSignatureInComment12]
222222
def f(): # type: (x) -> x x # comment #2
223223
pass
224224
[out]
225-
file:1: error: syntax error in type comment "(x) -> x x"
225+
file:1: error: Syntax error in type comment "(x) -> x x"
226226

227227

228228
[case testDuplicateSignatures1]
@@ -269,7 +269,7 @@ def g(*x, **y): # type: (*X, *Y) -> Z
269269
pass
270270
[out]
271271
file:1: error: Inconsistent use of "*" in function signature
272-
file:3: error: syntax error in type comment
272+
file:3: error: Syntax error in type comment
273273
file:3: error: Inconsistent use of "*" in function signature
274274
file:3: error: Inconsistent use of "**" in function signature
275275

0 commit comments

Comments
 (0)