Skip to content

Use double quotes in errors #10491

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 8 commits into from
May 17, 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 mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def generate_unused_ignore_errors(self, file: str) -> None:
for line in set(ignored_lines) - self.used_ignored_lines[file]:
# Don't use report since add_error_info will ignore the error!
info = ErrorInfo(self.import_context(), file, self.current_module(), None,
None, line, -1, 'error', "unused 'type: ignore' comment",
None, line, -1, 'error', 'unused "type: ignore" comment',
None, False, False)
self._add_error_info(file, info)

Expand Down
4 changes: 2 additions & 2 deletions mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2012,9 +2012,9 @@ def format_string_list(lst: List[str]) -> str:
def format_item_name_list(s: Iterable[str]) -> str:
lst = list(s)
if len(lst) <= 5:
return '(' + ', '.join(["'%s'" % name for name in lst]) + ')'
return '(' + ', '.join(['"%s"' % name for name in lst]) + ')'
else:
return '(' + ', '.join(["'%s'" % name for name in lst[:5]]) + ', ...)'
return '(' + ', '.join(['"%s"' % name for name in lst[:5]]) + ', ...)'


def callable_name(type: FunctionLike) -> Optional[str]:
Expand Down
22 changes: 11 additions & 11 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,7 @@ def visit_decorator(self, dec: Decorator) -> None:
def check_decorated_function_is_method(self, decorator: str,
context: Context) -> None:
if not self.type or self.is_func_scope():
self.fail("'%s' used with a non-method" % decorator, context)
self.fail('"%s" used with a non-method' % decorator, context)

#
# Classes
Expand Down Expand Up @@ -1645,7 +1645,7 @@ def verify_base_classes(self, defn: ClassDef) -> bool:
self.fail('Cycle in inheritance hierarchy', defn)
cycle = True
if baseinfo.fullname == 'builtins.bool':
self.fail("'%s' is not a valid base class" %
self.fail('"%s" is not a valid base class' %
baseinfo.name, defn, blocker=True)
return False
dup = find_duplicate(info.direct_base_classes())
Expand Down Expand Up @@ -3326,7 +3326,7 @@ def visit_expression_stmt(self, s: ExpressionStmt) -> None:
def visit_return_stmt(self, s: ReturnStmt) -> None:
self.statement = s
if not self.is_func_scope():
self.fail("'return' outside function", s)
self.fail('"return" outside function', s)
if s.expr:
s.expr.accept(self)

Expand Down Expand Up @@ -3385,12 +3385,12 @@ def visit_for_stmt(self, s: ForStmt) -> None:
def visit_break_stmt(self, s: BreakStmt) -> None:
self.statement = s
if self.loop_depth == 0:
self.fail("'break' outside loop", s, serious=True, blocker=True)
self.fail('"break" outside loop', s, serious=True, blocker=True)

def visit_continue_stmt(self, s: ContinueStmt) -> None:
self.statement = s
if self.loop_depth == 0:
self.fail("'continue' outside loop", s, serious=True, blocker=True)
self.fail('"continue" outside loop', s, serious=True, blocker=True)

def visit_if_stmt(self, s: IfStmt) -> None:
self.statement = s
Expand Down Expand Up @@ -3581,7 +3581,7 @@ def visit_star_expr(self, expr: StarExpr) -> None:

def visit_yield_from_expr(self, e: YieldFromExpr) -> None:
if not self.is_func_scope(): # not sure
self.fail("'yield from' outside function", e, serious=True, blocker=True)
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)
Expand Down Expand Up @@ -3718,11 +3718,11 @@ def check_fixed_args(self, expr: CallExpr, numargs: int,
if numargs == 1:
s = ''
if len(expr.args) != numargs:
self.fail("'%s' expects %d argument%s" % (name, numargs, s),
self.fail('"%s" expects %d argument%s' % (name, numargs, s),
expr)
return False
if expr.arg_kinds != [ARG_POS] * numargs:
self.fail("'%s' must be called with %s positional argument%s" %
self.fail('"%s" must be called with %s positional argument%s' %
(name, numargs, s), expr)
return False
return True
Expand Down Expand Up @@ -3963,7 +3963,7 @@ def visit__promote_expr(self, expr: PromoteExpr) -> None:

def visit_yield_expr(self, expr: YieldExpr) -> None:
if not self.is_func_scope():
self.fail("'yield' outside function", expr, serious=True, blocker=True)
self.fail('"yield" outside function', expr, serious=True, blocker=True)
else:
if self.function_stack[-1].is_coroutine:
if self.options.python_version < (3, 6):
Expand All @@ -3978,9 +3978,9 @@ def visit_yield_expr(self, expr: YieldExpr) -> None:

def visit_await_expr(self, expr: AwaitExpr) -> None:
if not self.is_func_scope():
self.fail("'await' outside function", expr)
self.fail('"await" outside function', expr)
elif not self.function_stack[-1].is_coroutine:
self.fail("'await' outside coroutine ('async def')", expr)
self.fail('"await" outside coroutine ("async def")', expr)
expr.expr.accept(self)

#
Expand Down
2 changes: 1 addition & 1 deletion mypy/typeanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ def visit_partial_type(self, t: PartialType) -> Type:
assert False, "Internal error: Unexpected partial type"

def visit_ellipsis_type(self, t: EllipsisType) -> Type:
self.fail("Unexpected '...'", t)
self.fail('Unexpected "..."', t)
return AnyType(TypeOfAny.from_error)

def visit_type_type(self, t: TypeType) -> Type:
Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-expressions.test
Original file line number Diff line number Diff line change
Expand Up @@ -782,13 +782,13 @@ divmod(f, d) # E: Unsupported operand types for divmod ("float" and "Decimal")
reveal_type(divmod(d, d)) # N: Revealed type is "Tuple[__main__.Decimal, __main__.Decimal]"

# Now some bad calls
divmod() # E: 'divmod' expects 2 arguments \
divmod() # E: "divmod" expects 2 arguments \
# E: Missing positional arguments "_x", "_y" in call to "divmod"
divmod(7) # E: 'divmod' expects 2 arguments \
divmod(7) # E: "divmod" expects 2 arguments \
# E: Missing positional argument "_y" in call to "divmod"
divmod(7, 8, 9) # E: 'divmod' expects 2 arguments \
divmod(7, 8, 9) # E: "divmod" expects 2 arguments \
# E: Too many arguments for "divmod"
divmod(_x=7, _y=9) # E: 'divmod' must be called with 2 positional arguments
divmod(_x=7, _y=9) # E: "divmod" must be called with 2 positional arguments

divmod('foo', 'foo') # E: Unsupported left operand type for divmod ("str")
divmod(i, 'foo') # E: Unsupported operand types for divmod ("int" and "str")
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-generic-alias.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ t3: list[str] # E: "list" is not subscriptable, use "typing.List" instead
t4: tuple
t5: tuple[int] # E: "tuple" is not subscriptable, use "typing.Tuple" instead
t6: tuple[int, str] # E: "tuple" is not subscriptable, use "typing.Tuple" instead
t7: tuple[int, ...] # E: Unexpected '...' \
t7: tuple[int, ...] # E: Unexpected "..." \
# E: "tuple" is not subscriptable, use "typing.Tuple" instead

t8: dict = {}
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-ignore.test
Original file line number Diff line number Diff line change
Expand Up @@ -217,12 +217,12 @@ def f() -> None: pass
[out]

[case testCannotIgnoreBlockingError]
yield # type: ignore # E: 'yield' outside function
yield # type: ignore # E: "yield" outside function

[case testIgnoreWholeModule1]
# flags: --warn-unused-ignores
# type: ignore
IGNORE # type: ignore # E: unused 'type: ignore' comment
IGNORE # type: ignore # E: unused "type: ignore" comment

[case testIgnoreWholeModule2]
# type: ignore
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -3671,7 +3671,7 @@ pass
[out]
[out2]
[out3]
tmp/a.py:2: error: unused 'type: ignore' comment
tmp/a.py:2: error: unused "type: ignore" comment

-- Test that a non cache_fine_grained run can use a fine-grained cache
[case testRegularUsesFgCache]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-narrowing.test
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ if weird_mixture["key"] is Key.B: # E: Invalid tuple index type (actual ty
else:
reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), Tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]"

if weird_mixture[0] is Key.B: # E: TypedDict key must be a string literal; expected one of ('key')
if weird_mixture[0] is Key.B: # E: TypedDict key must be a string literal; expected one of ("key")
reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), Tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]"
else:
reveal_type(weird_mixture) # N: Revealed type is "Union[TypedDict('__main__.KeyedTypedDict', {'key': Literal[__main__.Key.B]}), Tuple[Literal[__main__.Key.C], fallback=__main__.KeyedNamedTuple]]"
Expand Down
20 changes: 10 additions & 10 deletions test-data/unit/check-python38.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def f(): ... # E: Function is missing a return type annotation \
def d(f): ... # type: ignore
@d
# type: ignore
def f(): ... # type: ignore # E: unused 'type: ignore' comment
def f(): ... # type: ignore # E: unused "type: ignore" comment

[case testIgnoreDecoratedFunction2]
# flags: --disallow-untyped-defs
Expand Down Expand Up @@ -91,28 +91,28 @@ def g(x: int): ...

[case testIgnoreScopeUnused1]
# flags: --warn-unused-ignores
( # type: ignore # E: unused 'type: ignore' comment
"IGNORE" # type: ignore # E: unused 'type: ignore' comment
+ # type: ignore # E: unused 'type: ignore' comment
( # type: ignore # E: unused "type: ignore" comment
"IGNORE" # type: ignore # E: unused "type: ignore" comment
+ # type: ignore # E: unused "type: ignore" comment
0 # type: ignore
) # type: ignore # E: unused 'type: ignore' comment
) # type: ignore # E: unused "type: ignore" comment
[builtins fixtures/primitives.pyi]

[case testIgnoreScopeUnused2]
# flags: --warn-unused-ignores
( # type: ignore # E: unused 'type: ignore' comment
( # type: ignore # E: unused "type: ignore" comment
"IGNORE"
- # type: ignore
0 # type: ignore # E: unused 'type: ignore' comment
) # type: ignore # E: unused 'type: ignore' comment
0 # type: ignore # E: unused "type: ignore" comment
) # type: ignore # E: unused "type: ignore" comment

[case testIgnoreScopeUnused3]
# flags: --warn-unused-ignores
( # type: ignore # E: unused 'type: ignore' comment
( # type: ignore # E: unused "type: ignore" comment
"IGNORE"
/
0 # type: ignore
) # type: ignore # E: unused 'type: ignore' comment
) # type: ignore # E: unused "type: ignore" comment

[case testPEP570ArgTypesMissing]
# flags: --disallow-untyped-defs
Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-semanal-error.test
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ class C: # Forgot to add type params here
c = C(t=3) # type: C[int] # E: "C" expects no type arguments, but 1 given

[case testBreakOutsideLoop]
break # E: 'break' outside loop
break # E: "break" outside loop

[case testContinueOutsideLoop]
continue # E: 'continue' outside loop
continue # E: "continue" outside loop

[case testYieldOutsideFunction]
yield # E: 'yield' outside function
yield # E: "yield" outside function

[case testYieldFromOutsideFunction]
x = 1
yield from x # E: 'yield from' outside function
yield from x # E: "yield from" outside function

[case testImportFuncDup]

Expand Down
16 changes: 8 additions & 8 deletions test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ T = TypeVar('T')
def join(x: T, y: T) -> T: return x
ab = join(A(x='', y=1, z=''), B(x='', z=1))
ac = join(A(x='', y=1, z=''), C(x='', y=0, z=1))
ab['y'] # E: "y" is not a valid TypedDict key; expected one of ('x')
ac['a'] # E: "a" is not a valid TypedDict key; expected one of ('x', 'y')
ab['y'] # E: "y" is not a valid TypedDict key; expected one of ("x")
ac['a'] # E: "a" is not a valid TypedDict key; expected one of ("x", "y")
[builtins fixtures/dict.pyi]

[case testCannotGetItemOfTypedDictWithNonLiteralKey]
Expand All @@ -712,7 +712,7 @@ from typing import Union
TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
p = TaggedPoint(type='2d', x=42, y=1337)
def get_coordinate(p: TaggedPoint, key: str) -> Union[str, int]:
return p[key] # E: TypedDict key must be a string literal; expected one of ('type', 'x', 'y')
return p[key] # E: TypedDict key must be a string literal; expected one of ("type", "x", "y")
[builtins fixtures/dict.pyi]


Expand Down Expand Up @@ -746,7 +746,7 @@ from typing import Union
TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int})
p = TaggedPoint(type='2d', x=42, y=1337)
def set_coordinate(p: TaggedPoint, key: str, value: int) -> None:
p[key] = value # E: TypedDict key must be a string literal; expected one of ('type', 'x', 'y')
p[key] = value # E: TypedDict key must be a string literal; expected one of ("type", "x", "y")
[builtins fixtures/dict.pyi]


Expand Down Expand Up @@ -2095,11 +2095,11 @@ class TD(TypedDict):
foo: int

d: TD = {b'foo': 2} # E: Expected TypedDict key to be string literal
d[b'foo'] = 3 # E: TypedDict key must be a string literal; expected one of ('foo') \
d[b'foo'] = 3 # E: TypedDict key must be a string literal; expected one of ("foo") \
# E: Argument 1 has incompatible type "bytes"; expected "str"
d[b'foo'] # E: TypedDict key must be a string literal; expected one of ('foo')
d[3] # E: TypedDict key must be a string literal; expected one of ('foo')
d[True] # E: TypedDict key must be a string literal; expected one of ('foo')
d[b'foo'] # E: TypedDict key must be a string literal; expected one of ("foo")
d[3] # E: TypedDict key must be a string literal; expected one of ("foo")
d[True] # E: TypedDict key must be a string literal; expected one of ("foo")
[builtins fixtures/dict.pyi]
[typing fixtures/typing-typeddict.pyi]

Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-warnings.test
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ a = 1
if int():
a = 'a' # type: ignore
if int():
a = 2 # type: ignore # E: unused 'type: ignore' comment
a = 2 # type: ignore # E: unused "type: ignore" comment
if int():
a = 'b' # E: Incompatible types in assignment (expression has type "str", variable has type "int")

Expand All @@ -63,8 +63,8 @@ from m import * # type: ignore
[file m.py]
pass
[out]
main:3: error: unused 'type: ignore' comment
main:4: error: unused 'type: ignore' comment
main:3: error: unused "type: ignore" comment
main:4: error: unused "type: ignore" comment


-- No return
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/errorstream.test
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ break
==== Errors flushed ====
a.py:1: error: Unsupported operand types for + ("int" and "str")
==== Errors flushed ====
b.py:2: error: 'break' outside loop
b.py:2: error: "break" outside loop

[case testCycles]
import a
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/fine-grained-blockers.test
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ break
def f(x: int) -> None: pass
[out]
==
a.py:2: error: 'break' outside loop
a.py:2: error: "break" outside loop
==
main:2: error: Missing positional argument "x" in call to "f"

Expand Down Expand Up @@ -427,7 +427,7 @@ import blocker2
1()
[out]
==
<ROOT>/test-data/unit/lib-stub/blocker2.pyi:2: error: 'continue' outside loop
<ROOT>/test-data/unit/lib-stub/blocker2.pyi:2: error: "continue" outside loop
==
a.py:1: error: "int" not callable

Expand Down
Loading