Skip to content

Use double quotes errors 'in async function, 'Cannot determine type of' and 'syntax error in type comment' #10282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/error_code_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ In this example the definitions of ``x`` and ``y`` are circular:

class Problem:
def set_x(self) -> None:
# Error: Cannot determine type of 'y' [has-type]
# Error: Cannot determine type of "y" [has-type]
self.x = self.y

def set_y(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions mypy/fastparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def parse_type_comment(type_comment: str,
except SyntaxError:
if errors is not None:
stripped_type = type_comment.split("#", 2)[0].strip()
err_msg = "{} '{}'".format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
err_msg = '{} "{}"'.format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
errors.report(line, column, err_msg, blocker=True, code=codes.SYNTAX)
return None, None
else:
Expand Down Expand Up @@ -566,7 +566,7 @@ def do_func_def(self, n: Union[ast3.FunctionDef, ast3.AsyncFunctionDef],
arg_types.insert(0, AnyType(TypeOfAny.special_form))
except SyntaxError:
stripped_type = n.type_comment.split("#", 2)[0].strip()
err_msg = "{} '{}'".format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
err_msg = '{} "{}"'.format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
self.fail(err_msg, lineno, n.col_offset)
if n.type_comment and n.type_comment[0] not in ["(", "#"]:
self.note('Suggestion: wrap argument types in parentheses',
Expand Down
2 changes: 1 addition & 1 deletion mypy/fastparse2.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def visit_FunctionDef(self, n: ast27.FunctionDef) -> Statement:
arg_types.insert(0, AnyType(TypeOfAny.special_form))
except SyntaxError:
stripped_type = type_comment.split("#", 2)[0].strip()
err_msg = "{} '{}'".format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
err_msg = '{} "{}"'.format(TYPE_COMMENT_SYNTAX_ERROR, stripped_type)
self.fail(err_msg, lineno, n.col_offset)
arg_types = [AnyType(TypeOfAny.from_error)] * len(args)
return_type = AnyType(TypeOfAny.from_error)
Expand Down
4 changes: 2 additions & 2 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,10 @@ def string_interpolation_mixing_key_and_non_keys(self, context: Context) -> None
code=codes.STRING_FORMATTING)

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

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

def no_formal_self(self, name: str, item: CallableType, context: Context) -> None:
self.fail('Attribute function "%s" with type %s does not accept self argument'
Expand Down
4 changes: 2 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3566,7 +3566,7 @@ def visit_yield_from_expr(self, e: YieldFromExpr) -> None:
self.fail("'yield from' outside function", e, serious=True, blocker=True)
else:
if self.function_stack[-1].is_coroutine:
self.fail("'yield from' in async function", e, serious=True, blocker=True)
self.fail('"yield from" in async function', e, serious=True, blocker=True)
else:
self.function_stack[-1].is_generator = True
if e.expr:
Expand Down Expand Up @@ -3949,7 +3949,7 @@ def visit_yield_expr(self, expr: YieldExpr) -> None:
else:
if self.function_stack[-1].is_coroutine:
if self.options.python_version < (3, 6):
self.fail("'yield' in async function", expr, serious=True, blocker=True)
self.fail('"yield" in async function', expr, serious=True, blocker=True)
else:
self.function_stack[-1].is_generator = True
self.function_stack[-1].is_async_generator = True
Expand Down
12 changes: 6 additions & 6 deletions test-data/unit/check-async-await.test
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ async def f() -> None:
# flags: --python-version 3.5

async def f():
yield None # E: 'yield' in async function
yield None # E: "yield" in async function
async def g():
yield # E: 'yield' in async function
yield # E: "yield" in async function
async def h():
x = yield # E: 'yield' in async function
x = yield # E: "yield" in async function
[builtins fixtures/async_await.pyi]

[case testNoYieldFromInAsyncDef]
Expand All @@ -359,8 +359,8 @@ async def g():
x = yield from []
[builtins fixtures/async_await.pyi]
[out]
main:3: error: 'yield from' in async function
main:5: error: 'yield from' in async function
main:3: error: "yield from" in async function
main:5: error: "yield from" in async function

[case testNoAsyncDefInPY2_python2]

Expand Down Expand Up @@ -554,7 +554,7 @@ async def f() -> AsyncGenerator[int, None]:
pass

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

[builtins fixtures/dict.pyi]
[typing fixtures/typing-async.pyi]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -938,7 +938,7 @@ A.B = None # E: Cannot assign to a type
[targets __main__]

[case testAccessingClassAttributeWithTypeInferenceIssue]
x = C.x # E: Cannot determine type of 'x'
x = C.x # E: Cannot determine type of "x"
def f() -> int: return 1
class C:
x = f()
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-columns.test
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ y: Dict[int, int] = {
[builtins fixtures/dict.pyi]

[case testColumnCannotDetermineType]
(x) # E:2: Cannot determine type of 'x'
(x) # E:2: Cannot determine type of "x"
x = None

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

[case testColumnProperty]
class A:
Expand Down
10 changes: 5 additions & 5 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def f(): # E: Type signature has too many arguments [syntax]
# type: (int) -> None
1

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

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

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

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

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

Expand Down Expand Up @@ -700,8 +700,8 @@ main:2: error: Name "y" is not defined [name-defined]
x = y # type: int # type: ignored[foo]
x = y # type: int # type: ignored [foo]
[out]
main:1: error: syntax error in type comment 'int' [syntax]
main:2: error: syntax error in type comment 'int' [syntax]
main:1: error: syntax error in type comment "int" [syntax]
main:2: error: syntax error in type comment "int" [syntax]

[case testErrorCode__exit__Return]
class InvalidReturn:
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-fastparse.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[case testFastParseTypeCommentSyntaxError]

x = None # type: a : b # E: syntax error in type comment 'a : b'
x = None # type: a : b # E: syntax error in type comment "a : b"

[case testFastParseInvalidTypeComment]

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

def f(): # E: syntax error in type comment 'None -> None' # N: Suggestion: wrap argument types in parentheses
def f(): # E: syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses
# type: None -> None
pass

[case testFastParseFunctionAnnotationSyntaxErrorSpaces]

def f(): # E: syntax error in type comment 'None -> None' # N: Suggestion: wrap argument types in parentheses
def f(): # E: syntax error in type comment "None -> None" # N: Suggestion: wrap argument types in parentheses
# type: None -> None
pass

Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -5183,11 +5183,11 @@ class Sub(Base):

[builtins fixtures/property.pyi]
[out]
tmp/a.py:3: error: Cannot determine type of 'foo'
tmp/a.py:4: error: Cannot determine type of 'foo'
tmp/a.py:3: error: Cannot determine type of "foo"
tmp/a.py:4: error: Cannot determine type of "foo"
[out2]
tmp/a.py:3: error: Cannot determine type of 'foo'
tmp/a.py:4: error: Cannot determine type of 'foo'
tmp/a.py:3: error: Cannot determine type of "foo"
tmp/a.py:4: error: Cannot determine type of "foo"

[case testRedefinitionClass]
import b
Expand Down
10 changes: 5 additions & 5 deletions test-data/unit/check-inference.test
Original file line number Diff line number Diff line change
Expand Up @@ -1299,14 +1299,14 @@ class A: pass

[case testAccessGlobalVarBeforeItsTypeIsAvailable]
import typing
x.y # E: Cannot determine type of 'x'
x.y # E: Cannot determine type of "x"
x = object()
x.y # E: "object" has no attribute "y"

[case testAccessDataAttributeBeforeItsTypeIsAvailable]

a = None # type: A
a.x.y # E: Cannot determine type of 'x'
a.x.y # E: Cannot determine type of "x"
class A:
def __init__(self) -> None:
self.x = object()
Expand Down Expand Up @@ -1963,7 +1963,7 @@ class A:
[out]

[case testMultipassAndTopLevelVariable]
y = x # E: Cannot determine type of 'x'
y = x # E: Cannot determine type of "x"
y()
x = 1+0
[out]
Expand Down Expand Up @@ -2066,7 +2066,7 @@ y = ''
[case testMultipassAndCircularDependency]
class A:
def f(self) -> None:
self.x = self.y # E: Cannot determine type of 'y'
self.x = self.y # E: Cannot determine type of "y"

def g(self) -> None:
self.y = self.x
Expand Down Expand Up @@ -2146,7 +2146,7 @@ from typing import TypeVar, Callable
T = TypeVar('T')
def dec() -> Callable[[T], T]: pass

A.g # E: Cannot determine type of 'g'
A.g # E: Cannot determine type of "g"

class A:
@classmethod
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-literal.test
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ reveal_type(g2) # N: Revealed type is "def (x: Literal['A B'])"

[case testLiteralInvalidTypeComment]
from typing_extensions import Literal
def f(x): # E: syntax error in type comment '(A[) -> None'
def f(x): # E: syntax error in type comment "(A[) -> None"
# type: (A[) -> None
pass

Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -1398,7 +1398,7 @@ class C:
import a
b = 1 + 1
[out]
tmp/a.py:4: error: Cannot determine type of 'x2'
tmp/a.py:4: error: Cannot determine type of "x2"

[case testErrorInPassTwo1]
import b
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-multiple-inheritance.test
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ class C:
def dec(f: Callable[..., T]) -> Callable[..., T]:
return f
[out]
main:3: error: Cannot determine type of 'f' in base class 'B'
main:3: error: Cannot determine type of 'f' in base class 'C'
main:3: error: Cannot determine type of "f" in base class "B"
main:3: error: Cannot determine type of "f" in base class "C"

[case testMultipleInheritance_NestedClassesWithSameName]
class Mixin1:
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-optional.test
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ class A:

def f(self, x: Optional['A']) -> None:
assert x
lambda: (self.y, x.a) # E: Cannot determine type of 'y'
lambda: (self.y, x.a) # E: Cannot determine type of "y"
self.y = int()
[builtins fixtures/isinstancelist.pyi]

Expand Down
Loading