diff --git a/mypy/errors.py b/mypy/errors.py index 4344610fdbcb..b3f99916b244 100644 --- a/mypy/errors.py +++ b/mypy/errors.py @@ -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) diff --git a/mypy/messages.py b/mypy/messages.py index a4caa5eafc1b..9038660c8824 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -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]: diff --git a/mypy/semanal.py b/mypy/semanal.py index f157c795d939..60cfe22b8919 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -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 @@ -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()) @@ -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) @@ -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 @@ -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) @@ -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 @@ -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): @@ -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) # diff --git a/mypy/typeanal.py b/mypy/typeanal.py index 09824dd93e6c..ab32c5c8fa44 100644 --- a/mypy/typeanal.py +++ b/mypy/typeanal.py @@ -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: diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index b3f98f3e2791..a037c3ac4346 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -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") diff --git a/test-data/unit/check-generic-alias.test b/test-data/unit/check-generic-alias.test index b7b4707e855a..5cfe77b9c0fc 100644 --- a/test-data/unit/check-generic-alias.test +++ b/test-data/unit/check-generic-alias.test @@ -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 = {} diff --git a/test-data/unit/check-ignore.test b/test-data/unit/check-ignore.test index bf99bd230b8d..686dece1c911 100644 --- a/test-data/unit/check-ignore.test +++ b/test-data/unit/check-ignore.test @@ -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 diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index ae39599a18c6..5989828e1aef 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -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] diff --git a/test-data/unit/check-narrowing.test b/test-data/unit/check-narrowing.test index 4cded1fd1bfd..4fdd8f3b1033 100644 --- a/test-data/unit/check-narrowing.test +++ b/test-data/unit/check-narrowing.test @@ -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]]" diff --git a/test-data/unit/check-python38.test b/test-data/unit/check-python38.test index ee2f0721ab62..996218d4d7f8 100644 --- a/test-data/unit/check-python38.test +++ b/test-data/unit/check-python38.test @@ -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 @@ -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 diff --git a/test-data/unit/check-semanal-error.test b/test-data/unit/check-semanal-error.test index f77045537543..f91e3b1360c7 100644 --- a/test-data/unit/check-semanal-error.test +++ b/test-data/unit/check-semanal-error.test @@ -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] diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index 6d63961e7233..8b28d2ef9ace 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -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] @@ -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] @@ -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] @@ -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] diff --git a/test-data/unit/check-warnings.test b/test-data/unit/check-warnings.test index 6c75e243c228..165812531e60 100644 --- a/test-data/unit/check-warnings.test +++ b/test-data/unit/check-warnings.test @@ -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") @@ -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 diff --git a/test-data/unit/errorstream.test b/test-data/unit/errorstream.test index beece91d87f7..8a73748d27ff 100644 --- a/test-data/unit/errorstream.test +++ b/test-data/unit/errorstream.test @@ -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 diff --git a/test-data/unit/fine-grained-blockers.test b/test-data/unit/fine-grained-blockers.test index 7ef66b6753c8..ed7ed5783c79 100644 --- a/test-data/unit/fine-grained-blockers.test +++ b/test-data/unit/fine-grained-blockers.test @@ -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" @@ -427,7 +427,7 @@ import blocker2 1() [out] == -/test-data/unit/lib-stub/blocker2.pyi:2: error: 'continue' outside loop +/test-data/unit/lib-stub/blocker2.pyi:2: error: "continue" outside loop == a.py:1: error: "int" not callable diff --git a/test-data/unit/semanal-errors.test b/test-data/unit/semanal-errors.test index be8f967c9fb0..0e6094b92bd8 100644 --- a/test-data/unit/semanal-errors.test +++ b/test-data/unit/semanal-errors.test @@ -331,31 +331,31 @@ break def f(): break [out] -main:1: error: 'break' outside loop -main:3: error: 'break' outside loop +main:1: error: "break" outside loop +main:3: error: "break" outside loop [case testContinueOutsideLoop] continue def f(): continue [out] -main:1: error: 'continue' outside loop -main:3: error: 'continue' outside loop +main:1: error: "continue" outside loop +main:3: error: "continue" outside loop [case testReturnOutsideFunction] def f(): pass return return 1 [out] -main:2: error: 'return' outside function -main:3: error: 'return' outside function +main:2: error: "return" outside function +main:3: error: "return" outside function [case testYieldOutsideFunction] yield 1 yield [out] -main:1: error: 'yield' outside function -main:2: error: 'yield' outside function +main:1: error: "yield" outside function +main:2: error: "yield" outside function [case testInvalidLvalues1] 1 = 1 @@ -775,7 +775,7 @@ class A(Generic[t]): [out] [case testTestExtendPrimitives] -class C(bool): pass # E: 'bool' is not a valid base class +class C(bool): pass # E: "bool" is not a valid base class class A(int): pass # ok class B(float): pass # ok class D(str): pass # ok @@ -829,14 +829,14 @@ cast(str[str], None) # E: "str" expects no type arguments, but 1 given [case testInvalidNumberOfArgsToCast] from typing import cast -cast(str) # E: 'cast' expects 2 arguments -cast(str, None, None) # E: 'cast' expects 2 arguments +cast(str) # E: "cast" expects 2 arguments +cast(str, None, None) # E: "cast" expects 2 arguments [out] [case testInvalidKindsOfArgsToCast] from typing import cast -cast(str, *None) # E: 'cast' must be called with 2 positional arguments -cast(str, target=None) # E: 'cast' must be called with 2 positional arguments +cast(str, *None) # E: "cast" must be called with 2 positional arguments +cast(str, target=None) # E: "cast" must be called with 2 positional arguments [out] [case testInvalidAnyCall] @@ -868,7 +868,7 @@ from abc import abstractmethod @abstractmethod def foo(): pass [out] -main:3: error: 'abstractmethod' used with a non-method +main:3: error: "abstractmethod" used with a non-method [case testAbstractNestedFunction] import typing @@ -877,7 +877,7 @@ def g() -> None: @abstractmethod def foo(): pass [out] -main:4: error: 'abstractmethod' used with a non-method +main:4: error: "abstractmethod" used with a non-method [case testInvalidTypeDeclaration] import typing @@ -1169,8 +1169,8 @@ class A: def h(): pass [builtins fixtures/staticmethod.pyi] [out] -main:2: error: 'staticmethod' used with a non-method -main:6: error: 'staticmethod' used with a non-method +main:2: error: "staticmethod" used with a non-method +main:6: error: "staticmethod" used with a non-method [case testClassmethodAndNonMethod] import typing @@ -1182,12 +1182,12 @@ class A: def h(): pass [builtins fixtures/classmethod.pyi] [out] -main:2: error: 'classmethod' used with a non-method -main:6: error: 'classmethod' used with a non-method +main:2: error: "classmethod" used with a non-method +main:6: error: "classmethod" used with a non-method [case testNonMethodProperty] import typing -@property # E: 'property' used with a non-method +@property # E: "property" used with a non-method def f() -> int: pass [builtins fixtures/property.pyi] [out] diff --git a/test-data/unit/semanal-types.test b/test-data/unit/semanal-types.test index 0c0354a79aeb..19d2d037e032 100644 --- a/test-data/unit/semanal-types.test +++ b/test-data/unit/semanal-types.test @@ -703,7 +703,7 @@ MypyFile:1( [case testInvalidTupleType] from typing import Tuple -t = None # type: Tuple[int, str, ...] # E: Unexpected '...' +t = None # type: Tuple[int, str, ...] # E: Unexpected "..." [builtins fixtures/tuple.pyi] [out]