8000 Syntax error messages capitalization (#19114) · python/mypy@9f53138 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9f53138

Browse files
charulatalodhaCharulata Lodhaamansomething
authored
Syntax error messages capitalization (#19114)
Fixes ##19107 Cause of Issue: ```ast3``` parser raises exception with error message which sometimes non-standardized. eg : ``` error: expected an indented block after function definition on line 1 [syntax] ``` Resolution: - standardize the exception error message before report generation for syntax exceptions specifically Contributors: - Me and [@aman ](https://github.com/amansomething) --------- Co-authored-by: Charulata Lodha <clodha@bloomberg.net> Co-authored-by: amansomething <amansomething@users.noreply.github.com>
1 parent a9bb737 commit 9f53138

17 files changed

+146
-144
lines changed

mypy/fastparse.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ def parse(
270270
errors.report(
271271
e.lineno if e.lineno is not None else -1,
272272
e.offset,
273-
message,
273+
re.sub(
274+
r"^(\s*\w)", lambda m: m.group(1).upper(), message
275+
), # Standardizing error message
274276
blocker=True,
275277
code=codes.SYNTAX,
276278
)

mypy/test/teststubtest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ def test_mypy_build(self) -> None:
25812581
output = run_stubtest(stub="+", runtime="", options=[])
25822582
assert output == (
25832583
"error: not checking stubs due to failed mypy compile:\n{}.pyi:1: "
2584-
"error: invalid syntax [syntax]\n".format(TEST_MODULE_NAME)
2584+
"error: Invalid syntax [syntax]\n".format(TEST_MODULE_NAME)
25852585
)
25862586

25872587
output = run_stubtest(stub="def f(): ...\ndef f(): ...", runtime="", options=[])

test-data/unit/check-basic.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ x in 1, # E: Unsupported right operand type for in ("int")
289289
[case testTrailingCommaInIfParsing]
290290
if x in 1, : pass
291291
[out]
292-
main:1: error: invalid syntax
292+
main:1: error: Invalid syntax
293293

294294
[case testInitReturnTypeError]
295295
class C:

test-data/unit/check-columns.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
f()
55
1 +
66
[out]
7-
main:2:5: error: invalid syntax
7+
main:2:5: error: Invalid syntax
88

99
[case testColumnsNestedFunctions]
1010
import typing

test-data/unit/check-errorcodes.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ reveal_type(1) # N: Revealed type is "Literal[1]?"
3333
[case testErrorCodeSyntaxError]
3434
1 ''
3535
[out]
36-
main:1: error: invalid syntax [syntax]
36+
main:1: error: Invalid syntax [syntax]
3737
[out version==3.10.0]
38-
main:1: error: invalid syntax. Perhaps you forgot a comma? [syntax]
38+
main:1: error: Invalid syntax. Perhaps you forgot a comma? [syntax]
3939

4040
[case testErrorCodeSyntaxError2]
4141
def f(): # E: Type signature has too many arguments [syntax]

test-data/unit/check-expressions.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ None < None # E: Unsupported left operand type for < ("None")
18611861

18621862
[case testDictWithStarExpr]
18631863

1864-
b = {'z': 26, *a} # E: invalid syntax
1864+
b = {'z': 26, *a} # E: Invalid syntax
18651865
[builtins fixtures/dict.pyi]
18661866

18671867
[case testDictWithStarStarExpr]

test-data/unit/check-fastparse.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[case testFastParseSyntaxError]
22

3-
1 + # E: invalid syntax
3+
1 + # E: Invalid syntax
44

55
[case testFastParseTypeCommentSyntaxError]
66

@@ -158,7 +158,7 @@ def f(a, # type: A
158158

159159
[case testFastParsePerArgumentAnnotationsWithAnnotatedBareStar]
160160

161-
def f(*, # type: int # E: bare * has associated type comment
161+
def f(*, # type: int # E: Bare * has associated type comment
162162
x # type: str
163163
):
164164
# type: (...) -> int

test-data/unit/check-ignore.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ from m import a # type: ignore
3838
[file m.py]
3939
+
4040
[out]
41-
tmp/m.py:1: error: invalid syntax
41+
tmp/m.py:1: error: Invalid syntax
4242

4343
[case testIgnoreAppliesOnlyToMissing]
4444
import a # type: ignore
@@ -59,7 +59,7 @@ from m import * # type: ignore
5959
[file m.py]
6060
+
6161
[out]
62-
tmp/m.py:1: error: invalid syntax
62+
tmp/m.py:1: error: Invalid syntax
6363

6464
[case testIgnoreAssignmentTypeError]
6565
x = 1

test-data/unit/check-newsyntax.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[case testNewSyntaxSyntaxError]
2-
x: int: int # E: invalid syntax
2+
x: int: int # E: Invalid syntax
33
[out]
44

55
[case testNewSyntaxBasics]
@@ -126,4 +126,4 @@ reveal_type(f'{1}') # N: Revealed type is "builtins.str"
126126
# flags: --python-version 3.99
127127
x *** x this is what future python looks like public static void main String[] args await goto exit
128128
[out]
129-
main:2: error: invalid syntax; you likely need to run mypy using Python 3.99 or newer
129+
main:2: error: Invalid syntax; you likely need to run mypy using Python 3.99 or newer

test-data/unit/check-statements.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ def f() -> Iterator[List[int]]:
13111311

13121312
[case testYieldFromNotAppliedToNothing]
13131313
def h():
1314-
yield from # E: invalid syntax
1314+
yield from # E: Invalid syntax
13151315
[out]
13161316

13171317
[case testYieldFromAndYieldTogether]

test-data/unit/cmdline.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ some_file.py:11: error: Argument 1 to "some_interesting_method" of
896896
[file some_file.py]
897897
it_looks_like_we_started_typing_something_but_then. = did_not_notice(an_extra_dot)
898898
[out]
899-
some_file.py:1: error: invalid syntax [syntax]
899+
some_file.py:1: error: Invalid syntax [syntax]
900900
...ooks_like_we_started_typing_something_but_then. = did_not_notice(an_ex...
901901
^
902902
== Return code: 2
@@ -1035,15 +1035,15 @@ public static void main(String[] args)
10351035
[file pkg/y.py]
10361036
x: str = 0
10371037
[out]
1038-
pkg/x.py:1: error: invalid syntax
1038+
pkg/x.py:1: error: Invalid syntax
10391039
Found 1 error in 1 file (errors prevented further checking)
10401040
== Return code: 2
10411041
[out version>=3.10]
1042-
pkg/x.py:1: error: invalid syntax. Perhaps you forgot a comma?
1042+
pkg/x.py:1: error: Invalid syntax. Perhaps you forgot a comma?
10431043
Found 1 error in 1 file (errors prevented further checking)
10441044
== Return code: 2
10451045
[out version>=3.10.3]
1046-
pkg/x.py:1: error: invalid syntax
1046+
pkg/x.py:1: error: Invalid syntax
10471047
Found 1 error in 1 file (errors prevented further checking)
10481048
== Return code: 2
10491049

0 commit comments

Comments
 (0)
0