8000 Use double quotes in all error messages (#10053) · python/mypy@96cae4b · GitHub
[go: up one dir, main page]

Skip to content

Commit 96cae4b

Browse files
Use double quotes in all error messages (#10053)
Fixes #7445 Changed single quotes to double quotes in all error message. Changed test cases to accommodate the new changes
1 parent e609a31 commit 96cae4b

29 files changed

+202
-200
lines changed

docs/source/command_line.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ potentially problematic or redundant in some way.
459459
.. code-block:: python
460460
461461
def process(x: int) -> None:
462-
# Error: Right operand of 'or' is never evaluated
462+
# Error: Right operand of "or" is never evaluated
463463
if isinstance(x, int) or x > 7:
464464
# Error: Unsupported operand types for + ("int" and "str")
465465
print(x + "bad")

docs/source/error_code_list.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Example with an error:
208208
209209
class Bundle:
210210
def __init__(self) -> None:
211-
# Error: Need type annotation for 'items'
211+
# Error: Need type annotation for "items"
212212
# (hint: "items: List[<type>] = ...") [var-annotated]
213213
self.items = []
214214

docs/source/error_code_list2.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ incorrect control flow or conditional checks that are accidentally always true o
187187
# mypy: warn-unreachable
188188
189189
def example(x: int) -> None:
190-
# Error: Right operand of 'or' is never evaluated [unreachable]
190+
# Error: Right operand of "or" is never evaluated [unreachable]
191191
assert isinstance(x, int) or x == 'unused'
192192
193193
return
@@ -205,7 +205,7 @@ mypy generates an error if it thinks that an expression is redundant.
205205
# mypy: enable-error-code redundant-expr
206206
207207
def example(x: int) -> None:
208-
# Error: Left operand of 'and' is always true [redundant-expr]
208+
# Error: Left operand of "and" is always true [redundant-expr]
209209
if isinstance(x, int) and x > 0:
210210
pass
211211

docs/source/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ for example, when assigning an empty dictionary to some global value:
302302

303303
.. code-block:: python
304304
305-
my_global_dict = {} # Error: Need type annotation for 'my_global_dict'
305+
my_global_dict = {} # Error: Need type annotation for "my_global_dict"
306306
307307
You can teach mypy what type ``my_global_dict`` is meant to have by giving it
308308
a type hint. For example, if you knew this variable is supposed to be a dict

docs/source/type_inference_and_annotations.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ without some help:
7878

7979
.. code-block:: python
8080
81-
l = [] # Error: Need type annotation for 'l'
81+
l = [] # Error: Need type annotation for "l"
8282
8383
In these cases you can give the type explicitly using a type annotation:
8484

@@ -162,7 +162,7 @@ in the following statement:
162162
def foo(arg: List[int]) -> None:
163163
print('Items:', ', '.join(arg))
164164
165-
a = [] # Error: Need type annotation for 'a'
165+
a = [] # Error: Need type annotation for "a"
166166
foo(a)
167167
168168
Working around the 10000 issue is easy by adding a type annotation:

mypy/messages.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -687,7 +687,7 @@ def deleted_as_rvalue(self, typ: DeletedType, context: Context) -> None:
687687
if typ.source is None:
688688
s = ""
689689
else:
690-
s = " '{}'".format(typ.source)
690+
s = ' "{}"'.format(typ.source)
691691
self.fail('Trying to read deleted variable{}'.format(s), context)
692692

693693
def deleted_as_lvalue(self, typ: DeletedType, context: Context) -> None:
@@ -699,7 +699,7 @@ def deleted_as_lvalue(self, typ: DeletedType, context: Context) -> None:
699699
if typ.source is None:
700700
s = ""
701701
else:
702-
s = " '{}'".format(typ.source)
702+
s = ' "{}"'.format(typ.source)
703703
self.fail('Assignment to variable{} outside except: block'.format(s), context)
704704

705705
def no_variant_matches_arguments(self,
@@ -1101,7 +1101,7 @@ def need_annotation_for_var(self, node: SymbolNode, context: Context,
11011101
else:
11021102
needed = 'comment'
11031103

1104-
self.fail("Need type {} for '{}'{}".format(needed, unmangle(node.name), hint), context,
1104+
self.fail('Need type {} for "{}"{}'.format(needed, unmangle(node.name), hint), context,
11051105
code=codes.VAR_ANNOTATED)
11061106

11071107
def explicit_any(self, ctx: Context) -> None:
@@ -1160,10 +1160,12 @@ def typeddict_key_not_found(
11601160
self.fail('\'{}\' is not a valid TypedDict key; expected one of {}'.format(
11611161
item_name, format_item_name_list(typ.items.keys())), context)
11621162
else:
1163-
self.fail("TypedDict {} has no key '{}'".format(format_type(typ), item_name), context)
1163+
self.fail('TypedDict {} has no key "{}"'.format(
1164+
format_type(typ), item_name), context)
11641165
matches = best_matches(item_name, typ.items.keys())
11651166
if matches:
1166-
self.note("Did you mean {}?".format(pretty_seq(matches[:3], "or")), context)
1167+
self.note("Did you mean {}?".format(
1168+
pretty_seq(matches[:3], "or")), context)
11671169

11681170
def typeddict_context_ambiguous(
11691171
self,
@@ -1179,10 +1181,10 @@ def typeddict_key_cannot_be_deleted(
11791181
item_name: str,
11801182
context: Context) -> None:
11811183
if typ.is_anonymous():
1182-
self.fail("TypedDict key '{}' cannot be deleted".format(item_name),
1184+
self.fail('TypedDict key "{}" cannot be deleted'.format(item_name),
11831185
context)
11841186
else:
1185-
self.fail("Key '{}' of TypedDict {} cannot be deleted".format(
1187+
self.fail('Key "{}" of TypedDict {} cannot be deleted'.format(
11861188
item_name, format_type(typ)), context)
11871189

11881190
def typeddict_setdefault_arguments_inconsistent(
@@ -1235,8 +1237,8 @@ def typed_function_untyped_decorator(self, func_name: str, context: Context) ->
12351237

12361238
def bad_proto_variance(self, actual: int, tvar_name: str, expected: int,
12371239
context: Context) -> None:
1238-
msg = capitalize("{} type variable '{}' used in protocol where"
1239-
" {} one is expected".format(variance_string(actual),
1240+
msg = capitalize('{} type variable "{}" used in protocol where'
1241+
' {} one is expected'.format(variance_string(actual),
12401242
tvar_name,
12411243
variance_string(expected)))
12421244
self.fail(msg, context)
@@ -1280,14 +1282,14 @@ def redundant_left_operand(self, op_name: str, context: Context) -> None:
12801282
it does not change the truth value of the entire condition as a whole.
12811283
'op_name' should either be the string "and" or the string "or".
12821284
"""
1283-
self.redundant_expr("Left operand of '{}'".format(op_name), op_name == 'and', context)
1285+
self.redundant_expr('Left operand of "{}"'.format(op_name), op_name == 'and', context)
12841286

12851287
def unreachable_right_operand(self, op_name: str, context: Context) -> None:
12861288
"""Indicates that the right operand of a boolean expression is redundant:
12871289
it does not change the truth value of the entire condition as a whole.
12881290
'op_name' should either be the string "and" or the string "or".
12891291
"""
1290-
self.fail("Right operand of '{}' is never evaluated".format(op_name),
1292+
self.fail('Right operand of "{}" is never evaluated'.format(op_name),
12911293
context, code=codes.UNREACHABLE)
12921294

12931295
def redundant_condition_in_comprehension(self, truthiness: bool, context: Context) -> None:
@@ -1352,7 +1354,7 @@ def report_protocol_problems(self,
13521354
missing = get_missing_protocol_members(subtype, supertype)
13531355
if (missing and len(missing) < len(supertype.type.protocol_members) and
13541356
len(missing) <= MAX_ITEMS):
1355-
self.note("'{}' is missing following '{}' protocol member{}:"
1357+
self.note('"{}" is missing following "{}" protocol member{}:'
13561358
.format(subtype.type.name, supertype.type.name, plural_s(missing)),
13571359
context,
13581360
code=code)

test-data/unit/check-attr.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ A(1, [2], '3', 4, 5) # E: Too many arguments for "A"
7676
import attr
7777
@attr.s
7878
class A:
79-
a = attr.ib() # E: Need type annotation for 'a'
80-
_b = attr.ib() # E: Need type annotation for '_b'
81-
c = attr.ib(18) # E: Need type annotation for 'c'
82-
_d = attr.ib(validator=None, default=18) # E: Need type annotation for '_d'
79+
a = attr.ib() # E: Need type annotation for "a"
80+
_b = attr.ib() # E: Need type annotation for "_b"
81+
c = attr.ib(18) # E: Need type annotation for "c"
82+
_d = attr.ib(validator=None, default=18) # E: Need type annotation for "_d"
8383
E = 18
8484
[builtins fixtures/bool.pyi]
8585

@@ -959,9 +959,9 @@ class A:
959959
a: int
960960
b = 17
961961
# The following forms are not allowed with auto_attribs=True
962-
c = attr.ib() # E: Need type annotation for 'c'
963-
d, e = attr.ib(), attr.ib() # E: Need type annotation for 'd' # E: Need type annotation for 'e'
964-
f = g = attr.ib() # E: Need type annotation for 'f' # E: Need type annotation for 'g'
962+
c = attr.ib() # E: Need type annotation for "c"
963+
d, e = attr.ib(), attr.ib() # E: Need type annotation for "d" # E: Need type annotation for "e"
964+
f = g = attr.ib() # E: Need type annotation for "f" # E: Need type annotation for "g"
965965
[builtins fixtures/bool.pyi]
966966

967967
[case testAttrsRepeatedName]
@@ -1253,7 +1253,7 @@ import attr
12531253

12541254
@attr.s
12551255
class B:
1256-
x = attr.ib() # E: Need type annotation for 'x'
1256+
x = attr.ib() # E: Need type annotation for "x"
12571257

12581258
reveal_type(B) # N: Revealed type is 'def (x: Any) -> __main__.B'
12591259
[builtins fixtures/list.pyi]

test-data/unit/check-classes.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,7 @@ class C:
950950
x = C.x
951951
[builtins fixtures/list.pyi]
952952
[out]
953-
main:2: error: Need type annotation for 'x' (hint: "x: List[<type>] = ...")
953+
main:2: error: Need type annotation for "x" (hint: "x: List[<type>] = ...")
954954

955955
[case testAccessingGenericClassAttribute]
956956
from typing import Generic, TypeVar

test-data/unit/check-columns.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ if int():
200200

201201
[case testColumnNeedTypeAnnotation]
202202
if 1:
203-
x = [] # E:5: Need type annotation for 'x' (hint: "x: List[<type>] = ...")
203+
x = [] # E:5: Need type annotation for "x" (hint: "x: List[<type>] = ...")
204204
[builtins fixtures/list.pyi]
205205

206206
[case testColumnCallToUntypedFunction]
@@ -254,7 +254,7 @@ t: D = {'x':
254254
'y'} # E:5: Incompatible types (expression has type "str", TypedDict item "x" has type "int")
255255

256256
if int():
257-
del t['y'] # E:5: TypedDict "D" has no key 'y'
257+
del t['y'] # E:5: TypedDict "D" has no key "y"
258258
[builtins fixtures/dict.pyi]
259259
[typing fixtures/typing-typeddict.pyi]
260260

@@ -297,7 +297,7 @@ class C:
297297
p: P
298298
if int():
299299
p = C() # E:9: Incompatible types in assignment (expression has type "C", variable has type "P") \
300-
# N:9: 'C' is missing following 'P' protocol member: \
300+
# N:9: "C" is missing following "P" protocol member: \
301301
# N:9: y
302302

303303
[case testColumnRedundantCast]

test-data/unit/check-errorcodes.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,8 @@ from typing import TypeVar
259259

260260
T = TypeVar('T')
261261
def f() -> T: pass
262-
x = f() # E: Need type annotation for 'x' [var-annotated]
263-
y = [] # E: Need type annotation for 'y' (hint: "y: List[<type>] = ...") [var-annotated]
262+
x = f() # E: Need type annotation for "x" [var-annotated]
263+
y = [] # E: Need type annotation for "y" (hint: "y: List[<type>] = ...") [var-annotated]
264264
[builtins fixtures/list.pyi]
265265

266266
[case testErrorCodeBadOverride]
@@ -778,8 +778,8 @@ def foo() -> bool: ...
778778

779779
lst = [1, 2, 3, 4]
780780

781-
b = False or foo() # E: Left operand of 'or' is always false [redundant-expr]
782-
c = True and foo() # E: Left operand of 'and' is always true [redundant-expr]
781+
b = False or foo() # E: Left operand of "or" is always false [redundant-expr]
782+
c = True and foo() # E: Left operand of "and" is always true [redundant-expr]
783783
g = 3 if True else 4 # E: If condition is always true [redundant-expr]
784784
h = 3 if False else 4 # E: If condition is always false [redundant-expr]
785785
i = [x for x in lst if True] # E: If condition in comprehension is always true [redundant-expr]

test-data/unit/check-expressions.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,7 @@ d5 = dict(a=1, b='') # type: Dict[str, Any]
21702170

21712171
[case testDictWithoutKeywordArgs]
21722172
from typing import Dict
2173-
d = dict() # E: Need type annotation for 'd' (hint: "d: Dict[<type>, <type>] = ...")
2173+
d = dict() # E: Need type annotation for "d" (hint: "d: Dict[<type>, <type>] = ...")
21742174
d2 = dict() # type: Dict[int, str]
21752175
dict(undefined) # E: Name 'undefined' is not defined
21762176
[builtins fixtures/dict.pyi]
@@ -2390,8 +2390,8 @@ class B: ...
23902390
[builtins fixtures/dict.pyi]
23912391

23922392
[case testTypeAnnotationNeededMultipleAssignment]
2393-
x, y = [], [] # E: Need type annotation for 'x' (hint: "x: List[<type>] = ...") \
2394-
# E: Need type annotation for 'y' (hint: "y: List[<type>] = ...")
2393+
x, y = [], [] # E: Need type annotation for "x" (hint: "x: List[<type>] = ...") \
2394+
# E: Need type annotation for "y" (hint: "y: List[<type>] = ...")
23952395
[builtins fixtures/list.pyi]
23962396

23972397
[case testStrictEqualityEq]

test-data/unit/check-flags.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ def g(l: List[str]) -> None: pass # no error
14971497
def h(l: List[List]) -> None: pass # E: Missing type parameters for generic type "List"
14981498
def i(l: List[List[List[List]]]) -> None: pass # E: Missing type parameters for generic type "List"
14991499

1500-
x = [] # E: Need type annotation for 'x' (hint: "x: List[<type>] = ...")
1500+
x = [] # E: Need type annotation for "x" (hint: "x: List[<type>] = ...")
15011501
y: List = [] # E: Missing type parameters for generic type "List"
15021502
[builtins fixtures/list.pyi]
15031503

test-data/unit/check-functions.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,7 +1532,7 @@ if g(C()):
15321532
def f(x: B) -> B: pass
15331533

15341534
[case testRedefineFunctionDefinedAsVariableInitializedToEmptyList]
1535-
f = [] # E: Need type annotation for 'f' (hint: "f: List[<type>] = ...")
1535+
f = [] # E: Need type annotation for "f" (hint: "f: List[<type>] = ...")
15361536
if object():
15371537
def f(): pass # E: Incompatible redefinition
15381538
f() # E: "List[Any]" not callable
@@ -2344,7 +2344,7 @@ def make_list() -> List[T]: pass
23442344

23452345
l: List[int] = make_list()
23462346

2347-
bad = make_list() # E: Need type annotation for 'bad' (hint: "bad: List[<type>] = ...")
2347+
bad = make_list() # E: Need type annotation for "bad" (hint: "bad: List[<type>] = ...")
23482348
[builtins fixtures/list.pyi]
23492349

23502350
[case testAnonymousArgumentError]

test-data/unit/check-inference-context.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class B: pass
104104
from typing import TypeVar, Generic
105105
T = TypeVar('T')
106106
def g() -> None:
107-
x = f() # E: Need type annotation for 'x'
107+
x = f() # E: Need type annotation for "x"
108108

109109
def f() -> 'A[T]': pass
110110
class A(Generic[T]): pass
@@ -425,7 +425,7 @@ class B(A): pass
425425
[case testLocalVariableInferenceFromEmptyList]
426426
import typing
427427
def f() -> None:
428-
a = [] # E: Need type annotation for 'a' (hint: "a: List[<type>] = ...")
428+
a = [] # E: Need type annotation for "a" (hint: "a: List[<type>] = ...")
429429
b = [None]
430430
c = [B()]
431431
if int():

0 commit comments

Comments
 (0)
0