Skip to content

Commit e46aa6d

Browse files
authored
Use double quotes errors 'in async function, 'Cannot determine type of' and 'syntax error in type comment' (#10282)
* in async function - double quotes * Cannot determine type of - double quotes * syntax error in type comment - double quotes
1 parent 2a43cb9 commit e46aa6d

17 files changed

+58
-58
lines changed

docs/source/error_code_list.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ In this example the definitions of ``x`` and ``y`` are circular:
450450
451451
class Problem:
452452
def set_x(self) -> None:
453-
# Error: Cannot determine type of 'y' [has-type]
453+
# Error: Cannot determine type of "y" [has-type]
454454
self.x = self.y
455455
456456
def set_y(self) -> None:

mypy/fastparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def parse_type_comment(type_comment: str,
219219
except SyntaxError:
220220
if errors is not None:
221221
stripped_type = type_comment.split("#", 2)[0].strip()
222-
err_msg = "{} '{}'".format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
222+
err_msg = '{} "{}"'.format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
223223
errors.report(line, column, err_msg, blocker=True, code=codes.SYNTAX)
224224
return None, None
225225
else:
@@ -566,7 +566,7 @@ def do_func_def(self, n: Union[ast3.FunctionDef, ast3.AsyncFunctionDef],
566566
arg_types.insert(0, AnyType(TypeOfAny.special_form))
567567
except SyntaxError:
568568
stripped_type = n.type_comment.split("#", 2)[0].strip()
569-
err_msg = "{} '{}'".format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
569+
err_msg = '{} "{}"'.format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
570570
self.fail(err_msg, lineno, n.col_offset)
571571
if n.type_comment and n.type_comment[0] not in ["(", "#"]:
572572
self.note('Suggestion: wrap argument types in parentheses',

mypy/fastparse2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ def visit_FunctionDef(self, n: ast27.FunctionDef) -> Statement:
405405
arg_types.insert(0, AnyType(TypeOfAny.special_form))
406406
except SyntaxError:
407407
stripped_type = type_comment.split("#", 2)[0].strip()
408-
err_msg = "{} '{}'".format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
408+
err_msg = '{} "{}"'.format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
409409
self.fail(err_msg, lineno, n.col_offset)
410410
arg_types = [AnyType(TypeOfAny.from_error)] * len(args)
411411
return_type = AnyType(TypeOfAny.from_error)

mypy/messages.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,10 +909,10 @@ def string_interpolation_mixing_key_and_non_keys(self, context: Context) -> None
909909
code=codes.STRING_FORMATTING)
910910

911911
def cannot_determine_type(self, name: str, context: Context) -> None:
912-
self.fail("Cannot determine type of '%s'" % name, context, code=codes.HAS_TYPE)
912+
self.fail('Cannot determine type of "%s"' % name, context, code=codes.HAS_TYPE)
913913

914914
def cannot_determine_type_in_base(self, name: str, base: str, context: Context) -> None:
915-
self.fail("Cannot determine type of '%s' in base class '%s'" % (name, base), context)
915+
self.fail('Cannot determine type of "%s" in base class "%s"' % (name, base), context)
916916

917917
def no_formal_self(self, name: str, item: CallableType, context: Context) -> None:
918918
self.fail('Attribute function "%s" with type %s does not accept self argument'

mypy/semanal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3566,7 +3566,7 @@ def visit_yield_from_expr(self, e: YieldFromExpr) -> None:
35663566
self.fail("'yield from' outside function", e, serious=True, blocker=True)
35673567
else:
35683568
if self.function_stack[-1].is_coroutine:
3569-
self.fail("'yield from' in async function", e, serious=True, blocker=True)
3569+
self.fail('"yield from" in async function', e, serious=True, blocker=True)
35703570
else:
35713571
self.function_stack[-1].is_generator = True
35723572
if e.expr:
@@ -3949,7 +3949,7 @@ def visit_yield_expr(self, expr: YieldExpr) -> None:
39493949
else:
39503950
if self.function_stack[-1].is_coroutine:
39513951
if self.options.python_version < (3, 6):
3952-
self.fail("'yield' in async function", expr, serious=True, blocker=True)
3952+
self.fail('"yield" in async function', expr, serious=True, blocker=True)
39533953
else:
39543954
self.function_stack[-1].is_generator = True
39553955
self.function_stack[-1].is_async_generator = True

test-data/unit/check-async-await.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,11 @@ async def f() -> None:
344344
# flags: --python-version 3.5
345345

346346
async def f():
347-
yield None # E: 'yield' in async function
347+
yield None # E: "yield" in async function
348348
async def g():
349-
yield # E: 'yield' in async function
349+
yield # E: "yield" in async function
350350
async def h():
351-
x = yield # E: 'yield' in async function
351+
x = yield # E: "yield" in async function
352352
[builtins fixtures/async_await.pyi]
353353

354354
[case testNoYieldFromInAsyncDef]
@@ -359,8 +359,8 @@ async def g():
359359
x = yield from []
360360
[builtins fixtures/async_await.pyi]
361361
[out]
362-
main:3: error: 'yield from' in async function
363-
main:5: error: 'yield from' in async function
362+
main:3: error: "yield from" in async function
363+
main:5: error: "yield from" in async function
364364

365365
[case testNoAsyncDefInPY2_python2]
366366

@@ -554,7 +554,7 @@ async def f() -> AsyncGenerator[int, None]:
554554
pass
555555

556556
async def gen() -> AsyncGenerator[int, None]:
557-
yield from f() # E: 'yield from' in async function
557+
yield from f() # E: "yield from" in async function
558558

559559
[builtins fixtures/dict.pyi]
560560
[typing fixtures/typing-async.pyi]

test-data/unit/check-classes.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ A.B = None # E: Cannot assign to a type
938938
[targets __main__]
939939

940940
[case testAccessingClassAttributeWithTypeInferenceIssue]
941-
x = C.x # E: Cannot determine type of 'x'
941+
x = C.x # E: Cannot determine type of "x"
942942
def f() -> int: return 1
943943
class C:
944944
x = f()

test-data/unit/check-columns.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ y: Dict[int, int] = {
235235
[builtins fixtures/dict.pyi]
236236

237237
[case testColumnCannotDetermineType]
238-
(x) # E:2: Cannot determine type of 'x'
238+
(x) # E:2: Cannot determine type of "x"
239239
x = None
240240

241241
[case testColumnInvalidIndexing]
@@ -354,7 +354,7 @@ if int():
354354
# TODO: It would be better to point to the type comment
355355
xyz = 0 # type: blurbnard blarb
356356
[out]
357-
main:3:5: error: syntax error in type comment 'blurbnard blarb'
357+
main:3:5: error: syntax error in type comment "blurbnard blarb"
358358

359359
[case testColumnProperty]
360360
class A:

test-data/unit/check-errorcodes.test

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def f(): # E: Type signature has too many arguments [syntax]
3838
# type: (int) -> None
3939
1
4040

41-
x = 0 # type: x y # E: syntax error in type comment 'x y' [syntax]
41+
x = 0 # type: x y # E: syntax error in type comment "x y" [syntax]
4242

4343
[case testErrorCodeSyntaxError3]
4444
# This is a bit inconsistent -- syntax error would be more logical?
@@ -61,7 +61,7 @@ def f(): # E: Type signature has too many arguments [syntax]
6161
# type: (int) -> None
6262
1
6363

64-
x = 0 # type: x y # E: syntax error in type comment 'x y' [syntax]
64+
x = 0 # type: x y # E: syntax error in type comment "x y" [syntax]
6565

6666
[case testErrorCodeSyntaxError3_python2]
6767
def f(): pass
@@ -460,7 +460,7 @@ c = {} # E: Expected TypedDict key 'x' but found no keys [typeddict-item]
460460
[builtins fixtures/dict.pyi]
461461

462462
[case testErrorCodeCannotDetermineType]
463-
y = x # E: Cannot determine type of 'x' [has-type]
463+
y = x # E: Cannot determine type of "x" [has-type]
464464
reveal_type(y) # N: Revealed type is "Any"
465465
x = None
466466

@@ -700,8 +700,8 @@ main:2: error: Name "y" is not defined [name-defined]
700700
x = y # type: int # type: ignored[foo]
701701
x = y # type: int # type: ignored [foo]
702702
[out]
703-
main:1: error: syntax error in type comment 'int' [syntax]
704-
main:2: error: syntax error in type comment 'int' [syntax]
703+
main:1: error: syntax error in type comment "int" [syntax]
704+
main:2: error: syntax error in type comment "int" [syntax]
705705

706706
[case testErrorCode__exit__Return]
707707
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

0 commit comments

Comments
 (0)