diff --git a/docs/source/command_line.rst b/docs/source/command_line.rst index 8b8e7e6ee928..eb96e80b2ab4 100644 --- a/docs/source/command_line.rst +++ b/docs/source/command_line.rst @@ -435,7 +435,7 @@ potentially problematic or redundant in some way. .. code-block:: python def process(x: int) -> None: - # Error: Right operand of 'or' is never evaluated + # Error: Right operand of "or" is never evaluated if isinstance(x, int) or x > 7: # Error: Unsupported operand types for + ("int" and "str") print(x + "bad") diff --git a/docs/source/error_code_list.rst b/docs/source/error_code_list.rst index f1bf81fca51d..0b5898cdfd0b 100644 --- a/docs/source/error_code_list.rst +++ b/docs/source/error_code_list.rst @@ -208,7 +208,7 @@ Example with an error: class Bundle: def __init__(self) -> None: - # Error: Need type annotation for 'items' + # Error: Need type annotation for "items" # (hint: "items: List[] = ...") [var-annotated] self.items = [] diff --git a/docs/source/error_code_list2.rst b/docs/source/error_code_list2.rst index 6f12e8a8d5eb..d88525f33bb2 100644 --- a/docs/source/error_code_list2.rst +++ b/docs/source/error_code_list2.rst @@ -187,7 +187,7 @@ incorrect control flow or conditional checks that are accidentally always true o # mypy: warn-unreachable def example(x: int) -> None: - # Error: Right operand of 'or' is never evaluated [unreachable] + # Error: Right operand of "or" is never evaluated [unreachable] assert isinstance(x, int) or x == 'unused' return @@ -205,7 +205,7 @@ mypy generates an error if it thinks that an expression is redundant. # mypy: enable-error-code redundant-expr def example(x: int) -> None: - # Error: Left operand of 'and' is always true [redundant-expr] + # Error: Left operand of "and" is always true [redundant-expr] if isinstance(x, int) and x > 0: pass diff --git a/docs/source/getting_started.rst b/docs/source/getting_started.rst index 655f1c33c9ef..12c05c0d32e0 100644 --- a/docs/source/getting_started.rst +++ b/docs/source/getting_started.rst @@ -302,7 +302,7 @@ for example, when assigning an empty dictionary to some global value: .. code-block:: python - my_global_dict = {} # Error: Need type annotation for 'my_global_dict' + my_global_dict = {} # Error: Need type annotation for "my_global_dict" You can teach mypy what type ``my_global_dict`` is meant to have by giving it a type hint. For example, if you knew this variable is supposed to be a dict diff --git a/docs/source/type_inference_and_annotations.rst b/docs/source/type_inference_and_annotations.rst index cea01bcd2205..38518a8f2c3b 100644 --- a/docs/source/type_inference_and_annotations.rst +++ b/docs/source/type_inference_and_annotations.rst @@ -78,7 +78,7 @@ without some help: .. code-block:: python - l = [] # Error: Need type annotation for 'l' + l = [] # Error: Need type annotation for "l" In these cases you can give the type explicitly using a type annotation: @@ -162,7 +162,7 @@ in the following statement: def foo(arg: List[int]) -> None: print('Items:', ', '.join(arg)) - a = [] # Error: Need type annotation for 'a' + a = [] # Error: Need type annotation for "a" foo(a) Working around the issue is easy by adding a type annotation: diff --git a/mypy/messages.py b/mypy/messages.py index da9f783a61c1..0e54adb0030c 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -687,7 +687,7 @@ def deleted_as_rvalue(self, typ: DeletedType, context: Context) -> None: if typ.source is None: s = "" else: - s = " '{}'".format(typ.source) + s = ' "{}"'.format(typ.source) self.fail('Trying to read deleted variable{}'.format(s), context) def deleted_as_lvalue(self, typ: DeletedType, context: Context) -> None: @@ -699,7 +699,7 @@ def deleted_as_lvalue(self, typ: DeletedType, context: Context) -> None: if typ.source is None: s = "" else: - s = " '{}'".format(typ.source) + s = ' "{}"'.format(typ.source) self.fail('Assignment to variable{} outside except: block'.format(s), context) def no_variant_matches_arguments(self, @@ -1101,7 +1101,7 @@ def need_annotation_for_var(self, node: SymbolNode, context: Context, else: needed = 'comment' - self.fail("Need type {} for '{}'{}".format(needed, unmangle(node.name), hint), context, + self.fail('Need type {} for "{}"{}'.format(needed, unmangle(node.name), hint), context, code=codes.VAR_ANNOTATED) def explicit_any(self, ctx: Context) -> None: @@ -1160,10 +1160,12 @@ def typeddict_key_not_found( self.fail('\'{}\' is not a valid TypedDict key; expected one of {}'.format( item_name, format_item_name_list(typ.items.keys())), context) else: - self.fail("TypedDict {} has no key '{}'".format(format_type(typ), item_name), context) + self.fail('TypedDict {} has no key "{}"'.format( + format_type(typ), item_name), context) matches = best_matches(item_name, typ.items.keys()) if matches: - self.note("Did you mean {}?".format(pretty_seq(matches[:3], "or")), context) + self.note("Did you mean {}?".format( + pretty_seq(matches[:3], "or")), context) def typeddict_context_ambiguous( self, @@ -1179,10 +1181,10 @@ def typeddict_key_cannot_be_deleted( item_name: str, context: Context) -> None: if typ.is_anonymous(): - self.fail("TypedDict key '{}' cannot be deleted".format(item_name), + self.fail('TypedDict key "{}" cannot be deleted'.format(item_name), context) else: - self.fail("Key '{}' of TypedDict {} cannot be deleted".format( + self.fail('Key "{}" of TypedDict {} cannot be deleted'.format( item_name, format_type(typ)), context) def typeddict_setdefault_arguments_inconsistent( @@ -1235,8 +1237,8 @@ def typed_function_untyped_decorator(self, func_name: str, context: Context) -> def bad_proto_variance(self, actual: int, tvar_name: str, expected: int, context: Context) -> None: - msg = capitalize("{} type variable '{}' used in protocol where" - " {} one is expected".format(variance_string(actual), + msg = capitalize('{} type variable "{}" used in protocol where' + ' {} one is expected'.format(variance_string(actual), tvar_name, variance_string(expected))) self.fail(msg, context) @@ -1280,14 +1282,14 @@ def redundant_left_operand(self, op_name: str, context: Context) -> None: it does not change the truth value of the entire condition as a whole. 'op_name' should either be the string "and" or the string "or". """ - self.redundant_expr("Left operand of '{}'".format(op_name), op_name == 'and', context) + self.redundant_expr('Left operand of "{}"'.format(op_name), op_name == 'and', context) def unreachable_right_operand(self, op_name: str, context: Context) -> None: """Indicates that the right operand of a boolean expression is redundant: it does not change the truth value of the entire condition as a whole. 'op_name' should either be the string "and" or the string "or". """ - self.fail("Right operand of '{}' is never evaluated".format(op_name), + self.fail('Right operand of "{}" is never evaluated'.format(op_name), context, code=codes.UNREACHABLE) def redundant_condition_in_comprehension(self, truthiness: bool, context: Context) -> None: @@ -1352,7 +1354,7 @@ def report_protocol_problems(self, missing = get_missing_protocol_members(subtype, supertype) if (missing and len(missing) < len(supertype.type.protocol_members) and len(missing) <= MAX_ITEMS): - self.note("'{}' is missing following '{}' protocol member{}:" + self.note('"{}" is missing following "{}" protocol member{}:' .format(subtype.type.name, supertype.type.name, plural_s(missing)), context, code=code) diff --git a/test-data/unit/check-attr.test b/test-data/unit/check-attr.test index 844c022bc999..295b521bfa26 100644 --- a/test-data/unit/check-attr.test +++ b/test-data/unit/check-attr.test @@ -76,10 +76,10 @@ A(1, [2], '3', 4, 5) # E: Too many arguments for "A" import attr @attr.s class A: - a = attr.ib() # E: Need type annotation for 'a' - _b = attr.ib() # E: Need type annotation for '_b' - c = attr.ib(18) # E: Need type annotation for 'c' - _d = attr.ib(validator=None, default=18) # E: Need type annotation for '_d' + a = attr.ib() # E: Need type annotation for "a" + _b = attr.ib() # E: Need type annotation for "_b" + c = attr.ib(18) # E: Need type annotation for "c" + _d = attr.ib(validator=None, default=18) # E: Need type annotation for "_d" E = 18 [builtins fixtures/bool.pyi] @@ -959,9 +959,9 @@ class A: a: int b = 17 # The following forms are not allowed with auto_attribs=True - c = attr.ib() # E: Need type annotation for 'c' - d, e = attr.ib(), attr.ib() # E: Need type annotation for 'd' # E: Need type annotation for 'e' - f = g = attr.ib() # E: Need type annotation for 'f' # E: Need type annotation for 'g' + c = attr.ib() # E: Need type annotation for "c" + d, e = attr.ib(), attr.ib() # E: Need type annotation for "d" # E: Need type annotation for "e" + f = g = attr.ib() # E: Need type annotation for "f" # E: Need type annotation for "g" [builtins fixtures/bool.pyi] [case testAttrsRepeatedName] @@ -1253,7 +1253,7 @@ import attr @attr.s class B: - x = attr.ib() # E: Need type annotation for 'x' + x = attr.ib() # E: Need type annotation for "x" reveal_type(B) # N: Revealed type is 'def (x: Any) -> __main__.B' [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-classes.test b/test-data/unit/check-classes.test index 25ed01489958..49e52c2102a5 100644 --- a/test-data/unit/check-classes.test +++ b/test-data/unit/check-classes.test @@ -950,7 +950,7 @@ class C: x = C.x [builtins fixtures/list.pyi] [out] -main:2: error: Need type annotation for 'x' (hint: "x: List[] = ...") +main:2: error: Need type annotation for "x" (hint: "x: List[] = ...") [case testAccessingGenericClassAttribute] from typing import Generic, TypeVar diff --git a/test-data/unit/check-columns.test b/test-data/unit/check-columns.test index 00661e3b200c..f8a6442ac329 100644 --- a/test-data/unit/check-columns.test +++ b/test-data/unit/check-columns.test @@ -200,7 +200,7 @@ if int(): [case testColumnNeedTypeAnnotation] if 1: - x = [] # E:5: Need type annotation for 'x' (hint: "x: List[] = ...") + x = [] # E:5: Need type annotation for "x" (hint: "x: List[] = ...") [builtins fixtures/list.pyi] [case testColumnCallToUntypedFunction] @@ -254,7 +254,7 @@ t: D = {'x': 'y'} # E:5: Incompatible types (expression has type "str", TypedDict item "x" has type "int") if int(): - del t['y'] # E:5: TypedDict "D" has no key 'y' + del t['y'] # E:5: TypedDict "D" has no key "y" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -297,7 +297,7 @@ class C: p: P if int(): p = C() # E:9: Incompatible types in assignment (expression has type "C", variable has type "P") \ - # N:9: 'C' is missing following 'P' protocol member: \ + # N:9: "C" is missing following "P" protocol member: \ # N:9: y [case testColumnRedundantCast] diff --git a/test-data/unit/check-errorcodes.test b/test-data/unit/check-errorcodes.test index 8e959a4044e3..a6fb2f481a0c 100644 --- a/test-data/unit/check-errorcodes.test +++ b/test-data/unit/check-errorcodes.test @@ -259,8 +259,8 @@ from typing import TypeVar T = TypeVar('T') def f() -> T: pass -x = f() # E: Need type annotation for 'x' [var-annotated] -y = [] # E: Need type annotation for 'y' (hint: "y: List[] = ...") [var-annotated] +x = f() # E: Need type annotation for "x" [var-annotated] +y = [] # E: Need type annotation for "y" (hint: "y: List[] = ...") [var-annotated] [builtins fixtures/list.pyi] [case testErrorCodeBadOverride] @@ -778,8 +778,8 @@ def foo() -> bool: ... lst = [1, 2, 3, 4] -b = False or foo() # E: Left operand of 'or' is always false [redundant-expr] -c = True and foo() # E: Left operand of 'and' is always true [redundant-expr] +b = False or foo() # E: Left operand of "or" is always false [redundant-expr] +c = True and foo() # E: Left operand of "and" is always true [redundant-expr] g = 3 if True else 4 # E: If condition is always true [redundant-expr] h = 3 if False else 4 # E: If condition is always false [redundant-expr] i = [x for x in lst if True] # E: If condition in comprehension is always true [redundant-expr] diff --git a/test-data/unit/check-expressions.test b/test-data/unit/check-expressions.test index 1835aa248a7e..c434c0642db2 100644 --- a/test-data/unit/check-expressions.test +++ b/test-data/unit/check-expressions.test @@ -2170,7 +2170,7 @@ d5 = dict(a=1, b='') # type: Dict[str, Any] [case testDictWithoutKeywordArgs] from typing import Dict -d = dict() # E: Need type annotation for 'd' (hint: "d: Dict[, ] = ...") +d = dict() # E: Need type annotation for "d" (hint: "d: Dict[, ] = ...") d2 = dict() # type: Dict[int, str] dict(undefined) # E: Name 'undefined' is not defined [builtins fixtures/dict.pyi] @@ -2390,8 +2390,8 @@ class B: ... [builtins fixtures/dict.pyi] [case testTypeAnnotationNeededMultipleAssignment] -x, y = [], [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") \ - # E: Need type annotation for 'y' (hint: "y: List[] = ...") +x, y = [], [] # E: Need type annotation for "x" (hint: "x: List[] = ...") \ + # E: Need type annotation for "y" (hint: "y: List[] = ...") [builtins fixtures/list.pyi] [case testStrictEqualityEq] diff --git a/test-data/unit/check-flags.test b/test-data/unit/check-flags.test index 23f6280c61f0..400a67e77a8b 100644 --- a/test-data/unit/check-flags.test +++ b/test-data/unit/check-flags.test @@ -1497,7 +1497,7 @@ def g(l: List[str]) -> None: pass # no error def h(l: List[List]) -> None: pass # E: Missing type parameters for generic type "List" def i(l: List[List[List[List]]]) -> None: pass # E: Missing type parameters for generic type "List" -x = [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") +x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") y: List = [] # E: Missing type parameters for generic type "List" [builtins fixtures/list.pyi] diff --git a/test-data/unit/check-functions.test b/test-data/unit/check-functions.test index 6b05600dfa3c..2819f3299e57 100644 --- a/test-data/unit/check-functions.test +++ b/test-data/unit/check-functions.test @@ -1532,7 +1532,7 @@ if g(C()): def f(x: B) -> B: pass [case testRedefineFunctionDefinedAsVariableInitializedToEmptyList] -f = [] # E: Need type annotation for 'f' (hint: "f: List[] = ...") +f = [] # E: Need type annotation for "f" (hint: "f: List[] = ...") if object(): def f(): pass # E: Incompatible redefinition f() # E: "List[Any]" not callable @@ -2344,7 +2344,7 @@ def make_list() -> List[T]: pass l: List[int] = make_list() -bad = make_list() # E: Need type annotation for 'bad' (hint: "bad: List[] = ...") +bad = make_list() # E: Need type annotation for "bad" (hint: "bad: List[] = ...") [builtins fixtures/list.pyi] [case testAnonymousArgumentError] diff --git a/test-data/unit/check-inference-context.test b/test-data/unit/check-inference-context.test index bddf254c2721..c2f6d4e055ec 100644 --- a/test-data/unit/check-inference-context.test +++ b/test-data/unit/check-inference-context.test @@ -104,7 +104,7 @@ class B: pass from typing import TypeVar, Generic T = TypeVar('T') def g() -> None: - x = f() # E: Need type annotation for 'x' + x = f() # E: Need type annotation for "x" def f() -> 'A[T]': pass class A(Generic[T]): pass @@ -425,7 +425,7 @@ class B(A): pass [case testLocalVariableInferenceFromEmptyList] import typing def f() -> None: - a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") b = [None] c = [B()] if int(): diff --git a/test-data/unit/check-inference.test b/test-data/unit/check-inference.test index 750e00294ca3..c21b81f28e3f 100644 --- a/test-data/unit/check-inference.test +++ b/test-data/unit/check-inference.test @@ -441,7 +441,7 @@ class A: pass a = None # type: A def ff() -> None: - x = f() # E: Need type annotation for 'x' + x = f() # E: Need type annotation for "x" reveal_type(x) # N: Revealed type is 'Any' g(None) # Ok @@ -970,7 +970,7 @@ for x in [A()]: b = x # E: Incompatible types in assignment (expression has type "A", variable has type "B") a = x -for y in []: # E: Need type annotation for 'y' +for y in []: # E: Need type annotation for "y" a = y reveal_type(y) # N: Revealed type is 'Any' @@ -1016,8 +1016,8 @@ for x, y in [[A()]]: a = x a = y -for e, f in [[]]: # E: Need type annotation for 'e' \ - # E: Need type annotation for 'f' +for e, f in [[]]: # E: Need type annotation for "e" \ + # E: Need type annotation for "f" reveal_type(e) # N: Revealed type is 'Any' reveal_type(f) # N: Revealed type is 'Any' @@ -1055,7 +1055,7 @@ def f() -> None: if int(): a = B() \ # E: Incompatible types in assignment (expression has type "B", variable has type "A") - for a in []: pass # E: Need type annotation for 'a' + for a in []: pass # E: Need type annotation for "a" a = A() if int(): a = B() \ @@ -1379,18 +1379,18 @@ a.append(0) # E: Argument 1 to "append" of "list" has incompatible type "int"; [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyAndNotAnnotated] -a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyAndReadBeforeAppend] -a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") if a: pass a.xyz # E: "List[Any]" has no attribute "xyz" a.append('') [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyAndIncompleteTypeInAppend] -a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") a.append([]) a() # E: "List[Any]" not callable [builtins fixtures/list.pyi] @@ -1412,7 +1412,7 @@ def f() -> None: [case testInferListInitializedToEmptyAndNotAnnotatedInFunction] def f() -> None: - a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") def g() -> None: pass @@ -1422,7 +1422,7 @@ a.append(1) [case testInferListInitializedToEmptyAndReadBeforeAppendInFunction] def f() -> None: - a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") if a: pass a.xyz # E: "List[Any]" has no attribute "xyz" a.append('') @@ -1437,7 +1437,7 @@ class A: [case testInferListInitializedToEmptyAndNotAnnotatedInClassBody] class A: - a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") class B: a = [] @@ -1455,7 +1455,7 @@ class A: [case testInferListInitializedToEmptyAndNotAnnotatedInMethod] class A: def f(self) -> None: - a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") [builtins fixtures/list.pyi] [case testInferListInitializedToEmptyInMethodViaAttribute] @@ -1472,7 +1472,7 @@ from typing import List class A: def __init__(self) -> None: - self.x = [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") + self.x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") class B(A): # TODO?: This error is kind of a false positive, unfortunately @@ -1512,15 +1512,15 @@ a() # E: "Dict[str, int]" not callable [builtins fixtures/dict.pyi] [case testInferDictInitializedToEmptyUsingUpdateError] -a = {} # E: Need type annotation for 'a' (hint: "a: Dict[, ] = ...") +a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") a.update([1, 2]) # E: Argument 1 to "update" of "dict" has incompatible type "List[int]"; expected "Mapping[Any, Any]" a() # E: "Dict[Any, Any]" not callable [builtins fixtures/dict.pyi] [case testInferDictInitializedToEmptyAndIncompleteTypeInUpdate] -a = {} # E: Need type annotation for 'a' (hint: "a: Dict[, ] = ...") +a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") a[1] = {} -b = {} # E: Need type annotation for 'b' (hint: "b: Dict[, ] = ...") +b = {} # E: Need type annotation for "b" (hint: "b: Dict[, ] = ...") b[{}] = 1 [builtins fixtures/dict.pyi] @@ -1570,7 +1570,7 @@ if bool(): d = {1: 'x'} reveal_type(d) # N: Revealed type is 'builtins.dict[builtins.int*, builtins.str*]' -dd = {} # E: Need type annotation for 'dd' (hint: "dd: Dict[, ] = ...") +dd = {} # E: Need type annotation for "dd" (hint: "dd: Dict[, ] = ...") if bool(): dd = [1] # E: Incompatible types in assignment (expression has type "List[int]", variable has type "Dict[Any, Any]") reveal_type(dd) # N: Revealed type is 'builtins.dict[Any, Any]' @@ -1590,27 +1590,27 @@ reveal_type(oo) # N: Revealed type is 'collections.OrderedDict[builtins.int*, bu [builtins fixtures/dict.pyi] [case testEmptyCollectionAssignedToVariableTwiceIncremental] -x = [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") +x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") y = x x = [] reveal_type(x) # N: Revealed type is 'builtins.list[Any]' -d = {} # E: Need type annotation for 'd' (hint: "d: Dict[, ] = ...") +d = {} # E: Need type annotation for "d" (hint: "d: Dict[, ] = ...") z = d d = {} reveal_type(d) # N: Revealed type is 'builtins.dict[Any, Any]' [builtins fixtures/dict.pyi] [out2] -main:1: error: Need type annotation for 'x' (hint: "x: List[] = ...") +main:1: error: Need type annotation for "x" (hint: "x: List[] = ...") main:4: note: Revealed type is 'builtins.list[Any]' -main:5: error: Need type annotation for 'd' (hint: "d: Dict[, ] = ...") +main:5: error: Need type annotation for "d" (hint: "d: Dict[, ] = ...") main:8: note: Revealed type is 'builtins.dict[Any, Any]' [case testEmptyCollectionAssignedToVariableTwiceNoReadIncremental] -x = [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") +x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") x = [] [builtins fixtures/list.pyi] [out2] -main:1: error: Need type annotation for 'x' (hint: "x: List[] = ...") +main:1: error: Need type annotation for "x" (hint: "x: List[] = ...") [case testInferAttributeInitializedToEmptyAndAssigned] class C: @@ -1651,7 +1651,7 @@ reveal_type(C().a) # N: Revealed type is 'Union[builtins.int, None]' [case testInferAttributeInitializedToEmptyNonSelf] class C: def __init__(self) -> None: - self.a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + self.a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") if bool(): a = self a.a = [1] @@ -1662,7 +1662,7 @@ reveal_type(C().a) # N: Revealed type is 'builtins.list[Any]' [case testInferAttributeInitializedToEmptyAndAssignedOtherMethod] class C: def __init__(self) -> None: - self.a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + self.a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") def meth(self) -> None: self.a = [1] reveal_type(C().a) # N: Revealed type is 'builtins.list[Any]' @@ -1671,7 +1671,7 @@ reveal_type(C().a) # N: Revealed type is 'builtins.list[Any]' [case testInferAttributeInitializedToEmptyAndAppendedOtherMethod] class C: def __init__(self) -> None: - self.a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + self.a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") def meth(self) -> None: self.a.append(1) reveal_type(C().a) # N: Revealed type is 'builtins.list[Any]' @@ -1680,7 +1680,7 @@ reveal_type(C().a) # N: Revealed type is 'builtins.list[Any]' [case testInferAttributeInitializedToEmptyAndAssignedItemOtherMethod] class C: def __init__(self) -> None: - self.a = {} # E: Need type annotation for 'a' (hint: "a: Dict[, ] = ...") + self.a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") def meth(self) -> None: self.a[0] = 'yes' reveal_type(C().a) # N: Revealed type is 'builtins.dict[Any, Any]' @@ -1697,7 +1697,7 @@ reveal_type(C().a) # N: Revealed type is 'None' [case testInferAttributeInitializedToEmptyAndAssignedClassBody] class C: - a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") def __init__(self) -> None: self.a = [1] reveal_type(C().a) # N: Revealed type is 'builtins.list[Any]' @@ -1705,7 +1705,7 @@ reveal_type(C().a) # N: Revealed type is 'builtins.list[Any]' [case testInferAttributeInitializedToEmptyAndAppendedClassBody] class C: - a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") + a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") def __init__(self) -> None: self.a.append(1) reveal_type(C().a) # N: Revealed type is 'builtins.list[Any]' @@ -1713,7 +1713,7 @@ reveal_type(C().a) # N: Revealed type is 'builtins.list[Any]' [case testInferAttributeInitializedToEmptyAndAssignedItemClassBody] class C: - a = {} # E: Need type annotation for 'a' (hint: "a: Dict[, ] = ...") + a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") def __init__(self) -> None: self.a[0] = 'yes' reveal_type(C().a) # N: Revealed type is 'builtins.dict[Any, Any]' @@ -1833,7 +1833,7 @@ x.append('') # E: Argument 1 to "append" of "list" has incompatible type "str"; x = None if object(): # Promote from partial None to partial list. - x = [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") + x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") x [builtins fixtures/list.pyi] @@ -1842,7 +1842,7 @@ def f() -> None: x = None if object(): # Promote from partial None to partial list. - x = [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") + x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") [builtins fixtures/list.pyi] [out] @@ -1851,7 +1851,7 @@ def f() -> None: from typing import TypeVar, Dict T = TypeVar('T') def f(*x: T) -> Dict[int, T]: pass -x = None # E: Need type annotation for 'x' +x = None # E: Need type annotation for "x" if object(): x = f() [builtins fixtures/dict.pyi] @@ -1928,7 +1928,7 @@ class A: pass [builtins fixtures/for.pyi] [out] -main:3: error: Need type annotation for 'x' (hint: "x: List[] = ...") +main:3: error: Need type annotation for "x" (hint: "x: List[] = ...") [case testPartialTypeErrorSpecialCase3] class A: @@ -2094,9 +2094,9 @@ o = 1 [case testMultipassAndPartialTypesSpecialCase3] def f() -> None: - x = {} # E: Need type annotation for 'x' (hint: "x: Dict[, ] = ...") + x = {} # E: Need type annotation for "x" (hint: "x: Dict[, ] = ...") y = o - z = {} # E: Need type annotation for 'z' (hint: "z: Dict[, ] = ...") + z = {} # E: Need type annotation for "z" (hint: "z: Dict[, ] = ...") o = 1 [builtins fixtures/dict.pyi] [out] @@ -2283,7 +2283,7 @@ main:4: error: Invalid type: try using Literal[0] instead? class C: x = None def __init__(self) -> None: - self.x = [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") + self.x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") [builtins fixtures/list.pyi] [out] @@ -2344,7 +2344,7 @@ T = TypeVar('T') def f() -> T: pass class C: - x = f() # E: Need type annotation for 'x' + x = f() # E: Need type annotation for "x" def m(self) -> str: return 42 # E: Incompatible return value type (got "int", expected "str") @@ -2361,7 +2361,7 @@ T = TypeVar('T') def f(x: Optional[T] = None) -> T: pass class C: - x = f() # E: Need type annotation for 'x' + x = f() # E: Need type annotation for "x" def m(self) -> str: return 42 # E: Incompatible return value type (got "int", expected "str") @@ -2377,7 +2377,7 @@ T = TypeVar('T') def f(x: List[T]) -> T: pass class C: - x = f([]) # E: Need type annotation for 'x' + x = f([]) # E: Need type annotation for "x" def m(self) -> str: return 42 # E: Incompatible return value type (got "int", expected "str") @@ -2394,7 +2394,7 @@ if bool(): [case testLocalPartialTypesWithGlobalInitializedToNone] # flags: --local-partial-types -x = None # E: Need type annotation for 'x' +x = None # E: Need type annotation for "x" def f() -> None: global x @@ -2405,7 +2405,7 @@ reveal_type(x) # N: Revealed type is 'None' [case testLocalPartialTypesWithGlobalInitializedToNone2] # flags: --local-partial-types -x = None # E: Need type annotation for 'x' +x = None # E: Need type annotation for "x" def f(): global x @@ -2454,7 +2454,7 @@ reveal_type(a) # N: Revealed type is 'builtins.str' [case testLocalPartialTypesWithClassAttributeInitializedToNone] # flags: --local-partial-types class A: - x = None # E: Need type annotation for 'x' + x = None # E: Need type annotation for "x" def f(self) -> None: self.x = 1 @@ -2462,7 +2462,7 @@ class A: [case testLocalPartialTypesWithClassAttributeInitializedToEmptyDict] # flags: --local-partial-types class A: - x = {} # E: Need type annotation for 'x' (hint: "x: Dict[, ] = ...") + x = {} # E: Need type annotation for "x" (hint: "x: Dict[, ] = ...") def f(self) -> None: self.x[0] = '' @@ -2485,7 +2485,7 @@ reveal_type(a) # N: Revealed type is 'builtins.list[builtins.int]' [case testLocalPartialTypesWithGlobalInitializedToEmptyList2] # flags: --local-partial-types -a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") def f() -> None: a.append(1) @@ -2496,7 +2496,7 @@ reveal_type(a) # N: Revealed type is 'builtins.list[Any]' [case testLocalPartialTypesWithGlobalInitializedToEmptyList3] # flags: --local-partial-types -a = [] # E: Need type annotation for 'a' (hint: "a: List[] = ...") +a = [] # E: Need type annotation for "a" (hint: "a: List[] = ...") def f(): a.append(1) @@ -2518,7 +2518,7 @@ reveal_type(a) # N: Revealed type is 'builtins.dict[builtins.int, builtins.str]' [case testLocalPartialTypesWithGlobalInitializedToEmptyDict2] # flags: --local-partial-types -a = {} # E: Need type annotation for 'a' (hint: "a: Dict[, ] = ...") +a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") def f() -> None: a[0] = '' @@ -2529,7 +2529,7 @@ reveal_type(a) # N: Revealed type is 'builtins.dict[Any, Any]' [case testLocalPartialTypesWithGlobalInitializedToEmptyDict3] # flags: --local-partial-types -a = {} # E: Need type annotation for 'a' (hint: "a: Dict[, ] = ...") +a = {} # E: Need type annotation for "a" (hint: "a: Dict[, ] = ...") def f(): a[0] = '' @@ -2637,7 +2637,7 @@ from typing import List def f(x): pass class A: - x = None # E: Need type annotation for 'x' + x = None # E: Need type annotation for "x" def f(self, p: List[str]) -> None: self.x = f(p) @@ -2647,7 +2647,7 @@ class A: [case testLocalPartialTypesAccessPartialNoneAttribute] # flags: --local-partial-types class C: - a = None # E: Need type annotation for 'a' + a = None # E: Need type annotation for "a" def f(self, x) -> None: C.a.y # E: Item "None" of "Optional[Any]" has no attribute "y" @@ -2655,7 +2655,7 @@ class C: [case testLocalPartialTypesAccessPartialNoneAttribute] # flags: --local-partial-types class C: - a = None # E: Need type annotation for 'a' + a = None # E: Need type annotation for "a" def f(self, x) -> None: self.a.y # E: Item "None" of "Optional[Any]" has no attribute "y" @@ -2944,7 +2944,7 @@ T = TypeVar('T') def f(x: Optional[T] = None) -> Callable[..., T]: ... -x = f() # E: Need type annotation for 'x' +x = f() # E: Need type annotation for "x" y = x [case testDontNeedAnnotationForCallable] @@ -3050,16 +3050,16 @@ x = defaultdict(int) x[''] = 1 reveal_type(x) # N: Revealed type is 'collections.defaultdict[builtins.str, builtins.int]' -y = defaultdict(int) # E: Need type annotation for 'y' +y = defaultdict(int) # E: Need type annotation for "y" -z = defaultdict(int) # E: Need type annotation for 'z' +z = defaultdict(int) # E: Need type annotation for "z" z[''] = '' reveal_type(z) # N: Revealed type is 'collections.defaultdict[Any, Any]' [builtins fixtures/dict.pyi] [case testPartialDefaultDictInconsistentValueTypes] from collections import defaultdict -a = defaultdict(int) # E: Need type annotation for 'a' +a = defaultdict(int) # E: Need type annotation for "a" a[''] = '' a[''] = 1 reveal_type(a) # N: Revealed type is 'collections.defaultdict[builtins.str, builtins.int]' @@ -3096,32 +3096,32 @@ class A: self.x = defaultdict(list) self.x['x'].append(1) reveal_type(self.x) # N: Revealed type is 'collections.defaultdict[builtins.str, builtins.list[builtins.int]]' - self.y = defaultdict(list) # E: Need type annotation for 'y' + self.y = defaultdict(list) # E: Need type annotation for "y" s = self s.y['x'].append(1) -x = {} # E: Need type annotation for 'x' (hint: "x: Dict[, ] = ...") +x = {} # E: Need type annotation for "x" (hint: "x: Dict[, ] = ...") x['x'].append(1) -y = defaultdict(list) # E: Need type annotation for 'y' +y = defaultdict(list) # E: Need type annotation for "y" y[[]].append(1) [builtins fixtures/dict.pyi] [case testPartialDefaultDictSpecialCases2] from collections import defaultdict -x = defaultdict(lambda: [1]) # E: Need type annotation for 'x' +x = defaultdict(lambda: [1]) # E: Need type annotation for "x" x[1].append('') # E: Argument 1 to "append" of "list" has incompatible type "str"; expected "int" reveal_type(x) # N: Revealed type is 'collections.defaultdict[Any, builtins.list[builtins.int]]' -xx = defaultdict(lambda: {'x': 1}) # E: Need type annotation for 'xx' +xx = defaultdict(lambda: {'x': 1}) # E: Need type annotation for "xx" xx[1]['z'] = 3 reveal_type(xx) # N: Revealed type is 'collections.defaultdict[Any, builtins.dict[builtins.str, builtins.int]]' -y = defaultdict(dict) # E: Need type annotation for 'y' +y = defaultdict(dict) # E: Need type annotation for "y" y['x'][1] = [3] -z = defaultdict(int) # E: Need type annotation for 'z' +z = defaultdict(int) # E: Need type annotation for "z" z[1].append('') reveal_type(z) # N: Revealed type is 'collections.defaultdict[Any, Any]' [builtins fixtures/dict.pyi] @@ -3133,7 +3133,7 @@ x = defaultdict(list) x['a'] = [1, 2, 3] reveal_type(x) # N: Revealed type is 'collections.defaultdict[builtins.str, builtins.list[builtins.int*]]' -y = defaultdict(list) # E: Need type annotation for 'y' +y = defaultdict(list) # E: Need type annotation for "y" y['a'] = [] reveal_type(y) # N: Revealed type is 'collections.defaultdict[Any, Any]' [builtins fixtures/dict.pyi] diff --git a/test-data/unit/check-inline-config.test b/test-data/unit/check-inline-config.test index 9bcff53cb523..56e9ee8e5c05 100644 --- a/test-data/unit/check-inline-config.test +++ b/test-data/unit/check-inline-config.test @@ -61,7 +61,7 @@ import a [file a.py] # mypy: allow-any-generics, disallow-untyped-globals -x = [] # E: Need type annotation for 'x' (hint: "x: List[] = ...") +x = [] # E: Need type annotation for "x" (hint: "x: List[] = ...") from typing import List def foo() -> List: diff --git a/test-data/unit/check-literal.test b/test-data/unit/check-literal.test index 739637beeaf2..a47d05d44042 100644 --- a/test-data/unit/check-literal.test +++ b/test-data/unit/check-literal.test @@ -2223,20 +2223,20 @@ d: Outer reveal_type(d[a_key]) # N: Revealed type is 'builtins.int' reveal_type(d[b_key]) # N: Revealed type is 'builtins.str' -d[c_key] # E: TypedDict "Outer" has no key 'c' +d[c_key] # E: TypedDict "Outer" has no key "c" reveal_type(d.get(a_key, u)) # N: Revealed type is 'Union[builtins.int, __main__.Unrelated]' reveal_type(d.get(b_key, u)) # N: Revealed type is 'Union[builtins.str, __main__.Unrelated]' reveal_type(d.get(c_key, u)) # N: Revealed type is 'builtins.object' -reveal_type(d.pop(a_key)) # E: Key 'a' of TypedDict "Outer" cannot be deleted \ +reveal_type(d.pop(a_key)) # E: Key "a" of TypedDict "Outer" cannot be deleted \ # N: Revealed type is 'builtins.int' reveal_type(d.pop(b_key)) # N: Revealed type is 'builtins.str' -d.pop(c_key) # E: TypedDict "Outer" has no key 'c' +d.pop(c_key) # E: TypedDict "Outer" has no key "c" -del d[a_key] # E: Key 'a' of TypedDict "Outer" cannot be deleted +del d[a_key] # E: Key "a" of TypedDict "Outer" cannot be deleted del d[b_key] -del d[c_key] # E: TypedDict "Outer" has no key 'c' +del d[c_key] # E: TypedDict "Outer" has no key "c" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] [out] @@ -2275,7 +2275,7 @@ reveal_type(c.get(str_key_bad, u)) # N: Revealed type is 'builtins.object' a[int_key_bad] # E: Tuple index out of range b[int_key_bad] # E: Tuple index out of range -c[str_key_bad] # E: TypedDict "MyDict" has no key 'missing' +c[str_key_bad] # E: TypedDict "MyDict" has no key "missing" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] [out] @@ -2347,17 +2347,17 @@ reveal_type(test.get(bad_keys, 3)) # N: Revealed type is 'builtin del test[optional_keys] -test[bad_keys] # E: TypedDict "Test" has no key 'bad' -test.pop(good_keys) # E: Key 'a' of TypedDict "Test" cannot be deleted \ - # E: Key 'b' of TypedDict "Test" cannot be deleted -test.pop(bad_keys) # E: Key 'a' of TypedDict "Test" cannot be deleted \ - # E: TypedDict "Test" has no key 'bad' +test[bad_keys] # E: TypedDict "Test" has no key "bad" +test.pop(good_keys) # E: Key "a" of TypedDict "Test" cannot be deleted \ + # E: Key "b" of TypedDict "Test" cannot be deleted +test.pop(bad_keys) # E: Key "a" of TypedDict "Test" cannot be deleted \ + # E: TypedDict "Test" has no key "bad" test.setdefault(good_keys, 3) # E: Argument 2 to "setdefault" of "TypedDict" has incompatible type "int"; expected "A" test.setdefault(bad_keys, 3 ) # E: Argument 2 to "setdefault" of "TypedDict" has incompatible type "int"; expected "A" -del test[good_keys] # E: Key 'a' of TypedDict "Test" cannot be deleted \ - # E: Key 'b' of TypedDict "Test" cannot be deleted -del test[bad_keys] # E: Key 'a' of TypedDict "Test" cannot be deleted \ - # E: TypedDict "Test" has no key 'bad' +del test[good_keys] # E: Key "a" of TypedDict "Test" cannot be deleted \ + # E: Key "b" of TypedDict "Test" cannot be deleted +del test[bad_keys] # E: Key "a" of TypedDict "Test" cannot be deleted \ + # E: TypedDict "Test" has no key "bad" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] [out] @@ -2434,8 +2434,8 @@ x: Union[D1, D2] bad_keys: Literal['a', 'b', 'c', 'd'] good_keys: Literal['b', 'c'] -x[bad_keys] # E: TypedDict "D1" has no key 'd' \ - # E: TypedDict "D2" has no key 'a' +x[bad_keys] # E: TypedDict "D1" has no key "d" \ + # E: TypedDict "D2" has no key "a" reveal_type(x[good_keys]) # N: Revealed type is 'Union[__main__.B, __main__.C]' reveal_type(x.get(good_keys)) # N: Revealed type is 'Union[__main__.B, __main__.C]' diff --git a/test-data/unit/check-newsemanal.test b/test-data/unit/check-newsemanal.test index 476345c801da..1ccdbbce5760 100644 --- a/test-data/unit/check-newsemanal.test +++ b/test-data/unit/check-newsemanal.test @@ -2907,11 +2907,11 @@ T = TypeVar('T') def f(x: Optional[T] = None) -> T: ... -x = f() # E: Need type annotation for 'x' +x = f() # E: Need type annotation for "x" y = x def g() -> None: - x = f() # E: Need type annotation for 'x' + x = f() # E: Need type annotation for "x" y = x [case testNewAnalyzerLessErrorsNeedAnnotationList] @@ -2931,12 +2931,12 @@ class G(Generic[T]): ... def f(x: Optional[T] = None) -> G[T]: ... -x = f() # E: Need type annotation for 'x' +x = f() # E: Need type annotation for "x" y = x reveal_type(y) # N: Revealed type is '__main__.G[Any]' def g() -> None: - x = f() # E: Need type annotation for 'x' + x = f() # E: Need type annotation for "x" y = x reveal_type(y) # N: Revealed type is '__main__.G[Any]' diff --git a/test-data/unit/check-protocols.test b/test-data/unit/check-protocols.test index 30d33b917123..34c695d77fd2 100644 --- a/test-data/unit/check-protocols.test +++ b/test-data/unit/check-protocols.test @@ -155,7 +155,7 @@ if int(): x = B() # E: Incompatible types in assignment (expression has type "B", variable has type "P") if int(): x = c1 # E: Incompatible types in assignment (expression has type "C1", variable has type "P") \ - # N: 'C1' is missing following 'P' protocol member: \ + # N: "C1" is missing following "P" protocol member: \ # N: meth2 if int(): x = c2 @@ -192,7 +192,7 @@ if int(): x = C() # OK if int(): x = Cbad() # E: Incompatible types in assignment (expression has type "Cbad", variable has type "P2") \ - # N: 'Cbad' is missing following 'P2' protocol member: \ + # N: "Cbad" is missing following "P2" protocol member: \ # N: meth2 [case testProtocolMethodVsAttributeErrors] @@ -439,10 +439,10 @@ from typing import TypeVar, Protocol T = TypeVar('T') # In case of these errors we proceed with declared variance. -class Pco(Protocol[T]): # E: Invariant type variable 'T' used in protocol where covariant one is expected +class Pco(Protocol[T]): # E: Invariant type variable "T" used in protocol where covariant one is expected def meth(self) -> T: pass -class Pcontra(Protocol[T]): # E: Invariant type variable 'T' used in protocol where contravariant one is expected +class Pcontra(Protocol[T]): # E: Invariant type variable "T" used in protocol where contravariant one is expected def meth(self, x: T) -> None: pass class Pinv(Protocol[T]): @@ -478,11 +478,11 @@ T = TypeVar('T') S = TypeVar('S') T_co = TypeVar('T_co', covariant=True) -class P(Protocol[T, S]): # E: Invariant type variable 'T' used in protocol where covariant one is expected \ - # E: Invariant type variable 'S' used in protocol where contravariant one is expected +class P(Protocol[T, S]): # E: Invariant type variable "T" used in protocol where covariant one is expected \ + # E: Invariant type variable "S" used in protocol where contravariant one is expected def fun(self, callback: Callable[[T], S]) -> None: pass -class P2(Protocol[T_co]): # E: Covariant type variable 'T_co' used in protocol where invariant one is expected +class P2(Protocol[T_co]): # E: Covariant type variable "T_co" used in protocol where invariant one is expected lst: List[T_co] [builtins fixtures/list.pyi] @@ -490,7 +490,7 @@ class P2(Protocol[T_co]): # E: Covariant type variable 'T_co' used in protocol w from typing import Protocol, TypeVar T = TypeVar('T') -class P(Protocol[T]): # E: Invariant type variable 'T' used in protocol where covariant one is expected +class P(Protocol[T]): # E: Invariant type variable "T" used in protocol where covariant one is expected attr: int [case testGenericProtocolsInference1] @@ -616,7 +616,7 @@ class E(D[T]): def f(x: T) -> T: z: P2[T, T] = E[T]() y: P2[T, T] = D[T]() # E: Incompatible types in assignment (expression has type "D[T]", variable has type "P2[T, T]") \ - # N: 'D' is missing following 'P2' protocol member: \ + # N: "D" is missing following "P2" protocol member: \ # N: attr2 return x [builtins fixtures/isinstancelist.pyi] @@ -751,8 +751,8 @@ from typing import Protocol, TypeVar, Iterable, Sequence T_co = TypeVar('T_co', covariant=True) T_contra = TypeVar('T_contra', contravariant=True) -class Proto(Protocol[T_co, T_contra]): # E: Covariant type variable 'T_co' used in protocol where contravariant one is expected \ - # E: Contravariant type variable 'T_contra' used in protocol where covariant one is expected +class Proto(Protocol[T_co, T_contra]): # E: Covariant type variable "T_co" used in protocol where contravariant one is expected \ + # E: Contravariant type variable "T_contra" used in protocol where covariant one is expected def one(self, x: Iterable[T_co]) -> None: pass def other(self) -> Sequence[T_contra]: @@ -1675,7 +1675,7 @@ fun2(z) # E: Argument 1 to "fun2" has incompatible type "N"; expected "P[int, in # N: y: expected "int", got "str" fun(N2(1)) # E: Argument 1 to "fun" has incompatible type "N2"; expected "P[int, str]" \ - # N: 'N2' is missing following 'P' protocol member: \ + # N: "N2" is missing following "P" protocol member: \ # N: y reveal_type(fun3(z)) # N: Revealed type is 'builtins.object*' @@ -1844,7 +1844,7 @@ class C: def attr2(self) -> int: pass x: P = C() # E: Incompatible types in assignment (expression has type "C", variable has type "P") \ - # N: 'C' is missing following 'P' protocol member: \ + # N: "C" is missing following "P" protocol member: \ # N: attr3 \ # N: Following member(s) of "C" have conflicts: \ # N: attr1: expected "int", got "str" \ @@ -1853,7 +1853,7 @@ x: P = C() # E: Incompatible types in assignment (expression has type "C", varia def f(x: P) -> P: return C() # E: Incompatible return value type (got "C", expected "P") \ - # N: 'C' is missing following 'P' protocol member: \ + # N: "C" is missing following "P" protocol member: \ # N: attr3 \ # N: Following member(s) of "C" have conflicts: \ # N: attr1: expected "int", got "str" \ @@ -1861,7 +1861,7 @@ def f(x: P) -> P: # N: Protocol member P.attr2 expected settable variable, got read-only attribute f(C()) # E: Argument 1 to "f" has incompatible type "C"; expected "P" \ - # N: 'C' is missing following 'P' protocol member: \ + # N: "C" is missing following "P" protocol member: \ # N: attr3 \ # N: Following member(s) of "C" have conflicts: \ # N: attr1: expected "int", got "str" \ @@ -2551,7 +2551,7 @@ class Blooper: reveal_type([self, x]) # N: Revealed type is 'builtins.list[builtins.object*]' class Gleemer: - flap = [] # E: Need type annotation for 'flap' (hint: "flap: List[] = ...") + flap = [] # E: Need type annotation for "flap" (hint: "flap: List[] = ...") def gleem(self, x: Flapper) -> None: reveal_type([self, x]) # N: Revealed type is 'builtins.list[builtins.object*]' diff --git a/test-data/unit/check-python2.test b/test-data/unit/check-python2.test index 51ab5f96c655..fe51cb4b8c1a 100644 --- a/test-data/unit/check-python2.test +++ b/test-data/unit/check-python2.test @@ -363,5 +363,5 @@ b = none.__bool__() # E: "None" has no attribute "__bool__" [case testDictWithoutTypeCommentInPython2] # flags: --py2 -d = dict() # E: Need type comment for 'd' (hint: "d = ... \# type: Dict[, ]") +d = dict() # E: Need type comment for "d" (hint: "d = ... \# type: Dict[, ]") [builtins_py2 fixtures/floatdict_python2.pyi] diff --git a/test-data/unit/check-python38.test b/test-data/unit/check-python38.test index 7cb571cedc8d..1cdd6617bd48 100644 --- a/test-data/unit/check-python38.test +++ b/test-data/unit/check-python38.test @@ -371,7 +371,7 @@ reveal_type(z2) # E: Name 'z2' is not defined # N: Revealed type is 'Any' from typing import List def check_partial_list() -> None: - if (x := []): # E: Need type annotation for 'x' (hint: "x: List[] = ...") + if (x := []): # E: Need type annotation for "x" (hint: "x: List[] = ...") pass y: List[str] diff --git a/test-data/unit/check-selftype.test b/test-data/unit/check-selftype.test index 28742cf35a93..0299635fe4f5 100644 --- a/test-data/unit/check-selftype.test +++ b/test-data/unit/check-selftype.test @@ -569,7 +569,7 @@ SubP('no') # E: No overload variant of "SubP" matches argument type "str" \ # N: def [T] __init__(self, use_str: Literal[False]) -> SubP[T] # This is a bit unfortunate: we don't have a way to map the overloaded __init__ to subtype. -x = SubP(use_str=True) # E: Need type annotation for 'x' +x = SubP(use_str=True) # E: Need type annotation for "x" reveal_type(x) # N: Revealed type is '__main__.SubP[Any]' y: SubP[str] = SubP(use_str=True) @@ -595,7 +595,7 @@ class C(Generic[T]): from lib import PFallBack, PFallBackAny t: bool -xx = PFallBack(t) # E: Need type annotation for 'xx' +xx = PFallBack(t) # E: Need type annotation for "xx" yy = PFallBackAny(t) # OK [file lib.pyi] diff --git a/test-data/unit/check-statements.test b/test-data/unit/check-statements.test index 4502d18bb6f7..fff7906d5a02 100644 --- a/test-data/unit/check-statements.test +++ b/test-data/unit/check-statements.test @@ -451,7 +451,7 @@ del x raise e from a # E: Exception must be derived from BaseException raise e from e raise e from f -raise e from x # E: Trying to read deleted variable 'x' +raise e from x # E: Trying to read deleted variable "x" class A: pass class MyError(BaseException): pass [builtins fixtures/exception.pyi] @@ -797,8 +797,8 @@ try: pass except E1 as e: pass try: pass except E2 as e: pass -e + 1 # E: Trying to read deleted variable 'e' -e = E1() # E: Assignment to variable 'e' outside except: block +e + 1 # E: Trying to read deleted variable "e" +e = E1() # E: Assignment to variable "e" outside except: block [builtins fixtures/exception.pyi] [case testReuseDefinedTryExceptionVariable] @@ -810,8 +810,8 @@ def f(): e # Prevent redefinition e = 1 try: pass except E1 as e: pass -e = 1 # E: Assignment to variable 'e' outside except: block -e = E1() # E: Assignment to variable 'e' outside except: block +e = 1 # E: Assignment to variable "e" outside except: block +e = E1() # E: Assignment to variable "e" outside except: block [builtins fixtures/exception.pyi] [case testExceptionVariableReuseInDeferredNode1] @@ -1052,21 +1052,21 @@ del a.x, a.y # E: "A" has no attribute "y" a = 1 a + 1 del a -a + 1 # E: Trying to read deleted variable 'a' +a + 1 # E: Trying to read deleted variable "a" [builtins fixtures/ops.pyi] [case testDelStatementWithAssignmentTuple] a = 1 b = 1 del (a, b) -b + 1 # E: Trying to read deleted variable 'b' +b + 1 # E: Trying to read deleted variable "b" [builtins fixtures/ops.pyi] [case testDelStatementWithAssignmentList] a = 1 b = 1 del [a, b] -b + 1 # E: Trying to read deleted variable 'b' +b + 1 # E: Trying to read deleted variable "b" [builtins fixtures/list.pyi] [case testDelStatementWithAssignmentClass] @@ -1083,15 +1083,15 @@ c.a + 1 [case testDelStatementWithConditions] x = 5 del x -if x: ... # E: Trying to read deleted variable 'x' +if x: ... # E: Trying to read deleted variable "x" def f(x): return x if 0: ... -elif f(x): ... # E: Trying to read deleted variable 'x' +elif f(x): ... # E: Trying to read deleted variable "x" -while x == 5: ... # E: Trying to read deleted variable 'x' +while x == 5: ... # E: Trying to read deleted variable "x" -- Yield statement -- --------------- diff --git a/test-data/unit/check-tuples.test b/test-data/unit/check-tuples.test index 55bee11b699f..f8d38dab239b 100644 --- a/test-data/unit/check-tuples.test +++ b/test-data/unit/check-tuples.test @@ -514,8 +514,8 @@ d, e = f, g, h = 1, 1 # E: Need more than 2 values to unpack (3 expected) [case testAssignmentToStarMissingAnnotation] from typing import List t = 1, 2 -a, b, *c = 1, 2 # E: Need type annotation for 'c' (hint: "c: List[] = ...") -aa, bb, *cc = t # E: Need type annotation for 'cc' (hint: "cc: List[] = ...") +a, b, *c = 1, 2 # E: Need type annotation for "c" (hint: "c: List[] = ...") +aa, bb, *cc = t # E: Need type annotation for "cc" (hint: "cc: List[] = ...") [builtins fixtures/list.pyi] [case testAssignmentToStarAnnotation] @@ -823,7 +823,7 @@ for x in t: [case testForLoopOverEmptyTuple] import typing t = () -for x in t: pass # E: Need type annotation for 'x' +for x in t: pass # E: Need type annotation for "x" [builtins fixtures/for.pyi] [case testForLoopOverNoneValuedTuple] @@ -1217,7 +1217,7 @@ if int(): [builtins fixtures/tuple.pyi] [case testTupleWithoutContext] -a = (1, []) # E: Need type annotation for 'a' +a = (1, []) # E: Need type annotation for "a" [builtins fixtures/tuple.pyi] [case testTupleWithUnionContext] diff --git a/test-data/unit/check-typeddict.test b/test-data/unit/check-typeddict.test index 3c032d665161..146bb3c10000 100644 --- a/test-data/unit/check-typeddict.test +++ b/test-data/unit/check-typeddict.test @@ -682,7 +682,7 @@ reveal_type(c[u'value']) # N: Revealed type is 'builtins.int' from mypy_extensions import TypedDict TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int}) p: TaggedPoint -p['typ'] # E: TypedDict "TaggedPoint" has no key 'typ' \ +p['typ'] # E: TypedDict "TaggedPoint" has no key "typ" \ # N: Did you mean "type"? [builtins fixtures/dict.pyi] @@ -737,7 +737,7 @@ p['x'] = 'y' # E: Argument 2 has incompatible type "str"; expected "int" from mypy_extensions import TypedDict TaggedPoint = TypedDict('TaggedPoint', {'type': str, 'x': int, 'y': int}) p = TaggedPoint(type='2d', x=42, y=1337) -p['z'] = 1 # E: TypedDict "TaggedPoint" has no key 'z' +p['z'] = 1 # E: TypedDict "TaggedPoint" has no key "z" [builtins fixtures/dict.pyi] [case testCannotSetItemOfTypedDictWithNonLiteralKey] @@ -1600,7 +1600,7 @@ a.has_key('x') # E: "A" has no attribute "has_key" # TODO: Better error message a.clear() # E: "A" has no attribute "clear" -a.setdefault('invalid', 1) # E: TypedDict "A" has no key 'invalid' +a.setdefault('invalid', 1) # E: TypedDict "A" has no key "invalid" reveal_type(a.setdefault('x', 1)) # N: Revealed type is 'builtins.int' reveal_type(a.setdefault('y', [])) # N: Revealed type is 'builtins.list[builtins.int]' a.setdefault('y', '') # E: Argument 2 to "setdefault" of "TypedDict" has incompatible type "str"; expected "List[int]" @@ -1643,8 +1643,8 @@ reveal_type(a.pop('x')) # N: Revealed type is 'builtins.int' reveal_type(a.pop('y', [])) # N: Revealed type is 'builtins.list[builtins.int]' reveal_type(a.pop('x', '')) # N: Revealed type is 'Union[builtins.int, Literal['']?]' reveal_type(a.pop('x', (1, 2))) # N: Revealed type is 'Union[builtins.int, Tuple[Literal[1]?, Literal[2]?]]' -a.pop('invalid', '') # E: TypedDict "A" has no key 'invalid' -b.pop('x') # E: Key 'x' of TypedDict "B" cannot be deleted +a.pop('invalid', '') # E: TypedDict "A" has no key "invalid" +b.pop('x') # E: Key "x" of TypedDict "B" cannot be deleted x = '' b.pop(x) # E: Expected TypedDict key to be string literal pop = b.pop @@ -1662,8 +1662,8 @@ a: A b: B del a['x'] -del a['invalid'] # E: TypedDict "A" has no key 'invalid' -del b['x'] # E: Key 'x' of TypedDict "B" cannot be deleted +del a['invalid'] # E: TypedDict "A" has no key "invalid" +del b['x'] # E: Key "x" of TypedDict "B" cannot be deleted s = '' del a[s] # E: Expected TypedDict key to be string literal del b[s] # E: Expected TypedDict key to be string literal @@ -1694,7 +1694,7 @@ reveal_type(td.get('c')) # N: Revealed type is 'builtins.object*' reveal_type(td['a']) # N: Revealed type is 'builtins.int' reveal_type(td['b']) # N: Revealed type is 'Union[builtins.str, builtins.int]' reveal_type(td['c']) # N: Revealed type is 'Union[Any, builtins.int]' \ - # E: TypedDict "TDA" has no key 'c' + # E: TypedDict "TDA" has no key "c" [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] @@ -1715,7 +1715,7 @@ td: Union[TDA, TDB] reveal_type(td.pop('a')) # N: Revealed type is 'builtins.int' reveal_type(td.pop('b')) # N: Revealed type is 'Union[builtins.str, builtins.int]' -reveal_type(td.pop('c')) # E: TypedDict "TDA" has no key 'c' \ +reveal_type(td.pop('c')) # E: TypedDict "TDA" has no key "c" \ # N: Revealed type is 'Union[Any, builtins.int]' [builtins fixtures/dict.pyi] [typing fixtures/typing-typeddict.pyi] diff --git a/test-data/unit/check-typevar-values.test b/test-data/unit/check-typevar-values.test index affca2adab13..fbdd1baa8604 100644 --- a/test-data/unit/check-typevar-values.test +++ b/test-data/unit/check-typevar-values.test @@ -352,7 +352,7 @@ from typing import TypeVar, Generic X = TypeVar('X', int, str) class C(Generic[X]): def f(self, x: X) -> None: - self.x = x # E: Need type annotation for 'x' + self.x = x # E: Need type annotation for "x" ci: C[int] cs: C[str] reveal_type(ci.x) # N: Revealed type is 'Any' @@ -376,7 +376,7 @@ X = TypeVar('X', int, str) class C(Generic[X]): x: X def f(self) -> None: - self.y = self.x # E: Need type annotation for 'y' + self.y = self.x # E: Need type annotation for "y" ci: C[int] cs: C[str] reveal_type(ci.y) # N: Revealed type is 'Any' @@ -479,8 +479,8 @@ from typing import TypeVar T = TypeVar('T', int, str) class A: def f(self, x: T) -> None: - self.x = x # E: Need type annotation for 'x' - self.y = [x] # E: Need type annotation for 'y' + self.x = x # E: Need type annotation for "x" + self.y = [x] # E: Need type annotation for "y" self.z = 1 reveal_type(A().x) # N: Revealed type is 'Any' reveal_type(A().y) # N: Revealed type is 'Any' diff --git a/test-data/unit/check-unreachable-code.test b/test-data/unit/check-unreachable-code.test index 2632a2f349d5..d01088ae108a 100644 --- a/test-data/unit/check-unreachable-code.test +++ b/test-data/unit/check-unreachable-code.test @@ -897,12 +897,12 @@ def foo() -> bool: ... lst = [1, 2, 3, 4] -a = True or foo() # E: Right operand of 'or' is never evaluated -d = False and foo() # E: Right operand of 'and' is never evaluated -e = True or (True or (True or foo())) # E: Right operand of 'or' is never evaluated -f = (True or foo()) or (True or foo()) # E: Right operand of 'or' is never evaluated +a = True or foo() # E: Right operand of "or" is never evaluated +d = False and foo() # E: Right operand of "and" is never evaluated +e = True or (True or (True or foo())) # E: Right operand of "or" is never evaluated +f = (True or foo()) or (True or foo()) # E: Right operand of "or" is never evaluated -k = [x for x in lst if isinstance(x, int) or foo()] # E: Right operand of 'or' is never evaluated +k = [x for x in lst if isinstance(x, int) or foo()] # E: Right operand of "or" is never evaluated [builtins fixtures/isinstancelist.pyi] [case testUnreachableFlagMiscTestCaseMissingMethod] @@ -910,10 +910,10 @@ k = [x for x in lst if isinstance(x, int) or foo()] # E: Right operand of 'or' class Case1: def test1(self) -> bool: - return False and self.missing() # E: Right operand of 'and' is never evaluated + return False and self.missing() # E: Right operand of "and" is never evaluated def test2(self) -> bool: - return not self.property_decorator_missing and self.missing() # E: Right operand of 'and' is never evaluated + return not self.property_decorator_missing and self.missing() # E: Right operand of "and" is never evaluated def property_decorator_missing(self) -> bool: return True diff --git a/test-data/unit/fine-grained.test b/test-data/unit/fine-grained.test index e7f7c4dff094..7dac429a204b 100644 --- a/test-data/unit/fine-grained.test +++ b/test-data/unit/fine-grained.test @@ -2680,7 +2680,7 @@ class C(Generic[T]): pass [out] main:4: error: "object" has no attribute "C" == -main:4: error: Need type annotation for 'x' +main:4: error: Need type annotation for "x" [case testPartialTypeInNestedClass] import a @@ -2698,9 +2698,9 @@ def g() -> None: pass def g() -> int: pass [builtins fixtures/dict.pyi] [out] -main:7: error: Need type annotation for 'x' (hint: "x: Dict[, ] = ...") +main:7: error: Need type annotation for "x" (hint: "x: Dict[, ] = ...") == -main:7: error: Need type annotation for 'x' (hint: "x: Dict[, ] = ...") +main:7: error: Need type annotation for "x" (hint: "x: Dict[, ] = ...") [case testRefreshPartialTypeInClass] import a @@ -2716,9 +2716,9 @@ def g() -> None: pass def g() -> int: pass [builtins fixtures/dict.pyi] [out] -main:5: error: Need type annotation for 'x' (hint: "x: Dict[, ] = ...") +main:5: error: Need type annotation for "x" (hint: "x: Dict[, ] = ...") == -main:5: error: Need type annotation for 'x' (hint: "x: Dict[, ] = ...") +main:5: error: Need type annotation for "x" (hint: "x: Dict[, ] = ...") [case testRefreshPartialTypeInferredAttributeIndex] from c import C @@ -4164,9 +4164,9 @@ y = 0 [file a.py.2] y = '' [out] -main:4: error: Need type annotation for 'x' +main:4: error: Need type annotation for "x" == -main:4: error: Need type annotation for 'x' +main:4: error: Need type annotation for "x" [case testNonePartialType2] import a @@ -4182,9 +4182,9 @@ y = 0 [file a.py.2] y = '' [out] -main:4: error: Need type annotation for 'x' +main:4: error: Need type annotation for "x" == -main:4: error: Need type annotation for 'x' +main:4: error: Need type annotation for "x" [case testNonePartialType3] import a @@ -4196,7 +4196,7 @@ def f() -> None: y = '' [out] == -a.py:1: error: Need type annotation for 'y' +a.py:1: error: Need type annotation for "y" [case testNonePartialType4] import a @@ -4212,7 +4212,7 @@ def f() -> None: global y y = '' [out] -a.py:1: error: Need type annotation for 'y' +a.py:1: error: Need type annotation for "y" == [case testSkippedClass1] @@ -6128,7 +6128,7 @@ class P(Protocol): [out] == a.py:8: error: Argument 1 to "g" has incompatible type "C"; expected "P" -a.py:8: note: 'C' is missing following 'P' protocol member: +a.py:8: note: "C" is missing following "P" protocol member: a.py:8: note: y [case testProtocolRemoveAttrInClass] @@ -6153,7 +6153,7 @@ class P(Protocol): x: int [out] a.py:8: error: Incompatible types in assignment (expression has type "C", variable has type "P") -a.py:8: note: 'C' is missing following 'P' protocol member: +a.py:8: note: "C" is missing following "P" protocol member: a.py:8: note: y == @@ -6692,7 +6692,7 @@ class PBase(Protocol): [out] == a.py:4: error: Incompatible types in assignment (expression has type "SubP", variable has type "SuperP") -a.py:4: note: 'SubP' is missing following 'SuperP' protocol member: +a.py:4: note: "SubP" is missing following "SuperP" protocol member: a.py:4: note: z [case testProtocolVsProtocolSuperUpdated3] @@ -6729,7 +6729,7 @@ class NewP(Protocol): [out] == a.py:4: error: Incompatible types in assignment (expression has type "SubP", variable has type "SuperP") -a.py:4: note: 'SubP' is missing following 'SuperP' protocol member: +a.py:4: note: "SubP" is missing following "SuperP" protocol member: a.py:4: note: z [case testProtocolMultipleUpdates] @@ -6769,7 +6769,7 @@ class C2: [out] == a.py:2: error: Incompatible types in assignment (expression has type "C", variable has type "P") -a.py:2: note: 'C' is missing following 'P' protocol member: +a.py:2: note: "C" is missing following "P" protocol member: a.py:2: note: z == == diff --git a/test-data/unit/pythoneval.test b/test-data/unit/pythoneval.test index 6876744cbbb5..187d9c1c96a4 100644 --- a/test-data/unit/pythoneval.test +++ b/test-data/unit/pythoneval.test @@ -1121,7 +1121,7 @@ _testTypedDictMappingMethods.py:11: note: Revealed type is 'typing.ValuesView[bu _testTypedDictMappingMethods.py:12: note: Revealed type is 'TypedDict('_testTypedDictMappingMethods.Cell', {'value': builtins.int})' _testTypedDictMappingMethods.py:13: note: Revealed type is 'builtins.int' _testTypedDictMappingMethods.py:15: error: Unexpected TypedDict key 'invalid' -_testTypedDictMappingMethods.py:16: error: Key 'value' of TypedDict "Cell" cannot be deleted +_testTypedDictMappingMethods.py:16: error: Key "value" of TypedDict "Cell" cannot be deleted _testTypedDictMappingMethods.py:21: note: Revealed type is 'builtins.int' [case testCrashOnComplexCheckWithNamedTupleNext]