Skip to content

Commit 2a43cb9

Browse files
authored
Use double quotes errors 'is not defined' and 'Cannot instantiate' (#10278)
1 parent 2787d49 commit 2a43cb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+284
-284
lines changed

docs/source/common_issues.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ version of Python considers legal code. These can result in some of the
218218
following errors when trying to run your code:
219219

220220
* ``ImportError`` from circular imports
221-
* ``NameError: name 'X' is not defined`` from forward references
221+
* ``NameError: name "X" is not defined`` from forward references
222222
* ``TypeError: 'type' object is not subscriptable`` from types that are not generic at runtime
223223
* ``ImportError`` or ``ModuleNotFoundError`` from use of stub definitions not available at runtime
224224
* ``TypeError: unsupported operand type(s) for |: 'type' and 'type'`` from use of new syntax

docs/source/error_code_list.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ This example accidentally calls ``sort()`` instead of :py:func:`sorted`:
8787

8888
.. code-block:: python
8989
90-
x = sort([3, 2, 4]) # Error: Name 'sort' is not defined [name-defined]
90+
x = sort([3, 2, 4]) # Error: Name "sort" is not defined [name-defined]
9191
9292
Check arguments in calls [call-arg]
9393
-----------------------------------
@@ -565,7 +565,7 @@ Example:
565565
566566
... # No "save" method
567567
568-
# Error: Cannot instantiate abstract class 'Thing' with abstract attribute 'save' [abstract]
568+
# Error: Cannot instantiate abstract class "Thing" with abstract attribute "save" [abstract]
569569
t = Thing()
570570
571571
Check the target of NewType [valid-newtype]

docs/source/runtime_troubles.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ defined (aka forward reference). Thus this code does not work as expected:
108108

109109
.. code-block:: python
110110
111-
def f(x: A) -> None: ... # NameError: name 'A' is not defined
111+
def f(x: A) -> None: ... # NameError: name "A" is not defined
112112
class A: ...
113113
114114
Starting from Python 3.7, you can add ``from __future__ import annotations`` to

mypy/messages.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,9 +931,9 @@ def incompatible_conditional_function_def(self, defn: FuncDef) -> None:
931931
def cannot_instantiate_abstract_class(self, class_name: str,
932932
abstract_attributes: List[str],
933933
context: Context) -> None:
934-
attrs = format_string_list(["'%s'" % a for a in abstract_attributes])
935-
self.fail("Cannot instantiate abstract class '%s' with abstract "
936-
"attribute%s %s" % (class_name, plural_s(abstract_attributes),
934+
attrs = format_string_list(['"%s"' % a for a in abstract_attributes])
935+
self.fail('Cannot instantiate abstract class "%s" with abstract '
936+
'attribute%s %s' % (class_name, plural_s(abstract_attributes),
937937
attrs),
938938
context, code=codes.ABSTRACT)
939939

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4731,7 +4731,7 @@ def name_not_defined(self, name: str, ctx: Context, namespace: Optional[str] = N
47314731
# later on. Defer current target.
47324732
self.record_incomplete_ref()
47334733
return
4734-
message = "Name '{}' is not defined".format(name)
4734+
message = 'Name "{}" is not defined'.format(name)
47354735
self.fail(message, ctx, code=codes.NAME_DEFINED)
47364736

47374737
if 'builtins.{}'.format(name) in SUGGESTED_TEST_FIXTURES:

mypy/typeanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def try_analyze_special_unbound_type(self, t: UnboundType, fullname: str) -> Opt
286286
if self.api.is_incomplete_namespace('builtins'):
287287
self.api.record_incomplete_ref()
288288
else:
289-
self.fail("Name 'tuple' is not defined", t)
289+
self.fail('Name "tuple" is not defined', t)
290290
return AnyType(TypeOfAny.special_form)
291291
if len(t.args) == 0 and not t.empty_tuple_index:
292292
# Bare 'Tuple' is same as 'tuple'

mypyc/irbuild/ll_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def load_static_checked(self, typ: RType, identifier: str, module_name: Optional
593593
line: int = -1,
594594
error_msg: Optional[str] = None) -> Value:
595595
if error_msg is None:
596-
error_msg = "name '{}' is not defined".format(identifier)
596+
error_msg = 'name "{}" is not defined'.format(identifier)
597597
ok_block, error_block = BasicBlock(), BasicBlock()
598598
value = self.add(LoadStatic(typ, identifier, module_name, namespace, line=line))
599599
self.add(Branch(value, error_block, ok_block, Branch.IS_ERROR, rare=True))

mypyc/test-data/analysis.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ L6:
518518
(6, 0) {a} {a}
519519

520520
[case testError]
521-
def f(x: List[int]) -> None: pass # E: Name 'List' is not defined \
521+
def f(x: List[int]) -> None: pass # E: Name "List" is not defined \
522522
# N: Did you forget to import it from "typing"? (Suggestion: "from typing import List")
523523

524524
[case testExceptUndefined_Liveness]

mypyc/test-data/irbuild-basic.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,12 @@ def f() -> None:
539539
return 1 # E: No return value expected
540540

541541
[case testReportSemanticaAnalysisError1]
542-
def f(x: List[int]) -> None: pass # E: Name 'List' is not defined \
542+
def f(x: List[int]) -> None: pass # E: Name "List" is not defined \
543543
# N: Did you forget to import it from "typing"? (Suggestion: "from typing import List")
544544

545545
[case testReportSemanticaAnalysisError2]
546546
def f() -> None:
547-
x # E: Name 'x' is not defined
547+
x # E: Name "x" is not defined
548548

549549
[case testElif]
550550
def f(n: int) -> int:

mypyc/test-data/refcount.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ L0:
533533
return r1
534534

535535
[case testError]
536-
def f(x: List[int]) -> None: pass # E: Name 'List' is not defined \
536+
def f(x: List[int]) -> None: pass # E: Name "List" is not defined \
537537
# N: Did you forget to import it from "typing"? (Suggestion: "from typing import List")
538538

539539
[case testNewList]

test-data/unit/check-abstract.test

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class B(metaclass=ABCMeta):
157157
@abstractmethod
158158
def f(self): pass
159159
A() # OK
160-
B() # E: Cannot instantiate abstract class 'B' with abstract attribute 'f'
160+
B() # E: Cannot instantiate abstract class "B" with abstract attribute "f"
161161
[out]
162162

163163
[case testInstantiatingClassWithInheritedAbstractMethod]
@@ -169,7 +169,7 @@ class A(metaclass=ABCMeta):
169169
@abstractmethod
170170
def g(self): pass
171171
class B(A): pass
172-
B() # E: Cannot instantiate abstract class 'B' with abstract attributes 'f' and 'g'
172+
B() # E: Cannot instantiate abstract class "B" with abstract attributes "f" and "g"
173173
[out]
174174

175175
[case testInstantiationAbstractsInTypeForFunctions]
@@ -187,7 +187,7 @@ class C(B):
187187
def f(cls: Type[A]) -> A:
188188
return cls() # OK
189189
def g() -> A:
190-
return A() # E: Cannot instantiate abstract class 'A' with abstract attribute 'm'
190+
return A() # E: Cannot instantiate abstract class "A" with abstract attribute "m"
191191

192192
f(A) # E: Only concrete class can be given where "Type[A]" is expected
193193
f(B) # E: Only concrete class can be given where "Type[A]" is expected
@@ -213,7 +213,7 @@ def f(cls: Type[A]) -> A:
213213

214214
Alias = A
215215
GoodAlias = C
216-
Alias() # E: Cannot instantiate abstract class 'A' with abstract attribute 'm'
216+
Alias() # E: Cannot instantiate abstract class "A" with abstract attribute "m"
217217
GoodAlias()
218218
f(Alias) # E: Only concrete class can be given where "Type[A]" is expected
219219
f(GoodAlias)
@@ -293,7 +293,7 @@ class A(metaclass=ABCMeta):
293293
def i(self): pass
294294
@abstractmethod
295295
def j(self): pass
296-
a = A() # E: Cannot instantiate abstract class 'A' with abstract attributes 'a', 'b', ... and 'j' (7 methods suppressed)
296+
a = A() # E: Cannot instantiate abstract class "A" with abstract attributes "a", "b", ... and "j" (7 methods suppressed)
297297
[out]
298298

299299

@@ -524,8 +524,8 @@ class D(A, B):
524524
class E(A, B):
525525
def f(self) -> None: pass
526526
def g(self) -> None: pass
527-
C() # E: Cannot instantiate abstract class 'C' with abstract attribute 'g'
528-
D() # E: Cannot instantiate abstract class 'D' with abstract attribute 'f'
527+
C() # E: Cannot instantiate abstract class "C" with abstract attribute "g"
528+
D() # E: Cannot instantiate abstract class "D" with abstract attribute "f"
529529
E()
530530

531531
[case testInconsistentMro]
@@ -555,7 +555,7 @@ class B(A):
555555
def f(self, x: int) -> int: pass
556556
@overload
557557
def f(self, x: str) -> str: pass
558-
A() # E: Cannot instantiate abstract class 'A' with abstract attribute 'f'
558+
A() # E: Cannot instantiate abstract class "A" with abstract attribute "f"
559559
B()
560560
B().f(1)
561561
a = B() # type: A
@@ -585,7 +585,7 @@ class B(A):
585585
def f(self, x: int) -> int: pass
586586
@overload
587587
def f(self, x: str) -> str: pass
588-
A() # E: Cannot instantiate abstract class 'A' with abstract attribute 'f'
588+
A() # E: Cannot instantiate abstract class "A" with abstract attribute "f"
589589
B()
590590
B().f(1)
591591
a = B() # type: A
@@ -738,7 +738,7 @@ class A(metaclass=ABCMeta):
738738
@abstractproperty
739739
def x(self) -> int: pass
740740
class B(A): pass
741-
b = B() # E: Cannot instantiate abstract class 'B' with abstract attribute 'x'
741+
b = B() # E: Cannot instantiate abstract class "B" with abstract attribute "x"
742742

743743
[case testInstantiateClassWithReadWriteAbstractProperty]
744744
from abc import abstractproperty, ABCMeta
@@ -748,7 +748,7 @@ class A(metaclass=ABCMeta):
748748
@x.setter
749749
def x(self, x: int) -> None: pass
750750
class B(A): pass
751-
b = B() # E: Cannot instantiate abstract class 'B' with abstract attribute 'x'
751+
b = B() # E: Cannot instantiate abstract class "B" with abstract attribute "x"
752752

753753
[case testImplementAbstractPropertyViaProperty]
754754
from abc import abstractproperty, ABCMeta
@@ -803,7 +803,7 @@ b.x.y # E
803803
[builtins fixtures/property.pyi]
804804
[out]
805805
main:7: error: Property "x" defined in "A" is read-only
806-
main:8: error: Cannot instantiate abstract class 'B' with abstract attribute 'x'
806+
main:8: error: Cannot instantiate abstract class "B" with abstract attribute "x"
807807
main:9: error: "int" has no attribute "y"
808808

809809
[case testSuperWithAbstractProperty]
@@ -952,15 +952,15 @@ class A:
952952

953953
class C(B): pass
954954

955-
A.B() # E: Cannot instantiate abstract class 'B' with abstract attribute 'f'
956-
A.C() # E: Cannot instantiate abstract class 'C' with abstract attribute 'f'
955+
A.B() # E: Cannot instantiate abstract class "B" with abstract attribute "f"
956+
A.C() # E: Cannot instantiate abstract class "C" with abstract attribute "f"
957957

958958
[case testAbstractNewTypeAllowed]
959959
from typing import NewType, Mapping
960960

961961
Config = NewType('Config', Mapping[str, str])
962962

963-
bad = Mapping[str, str]() # E: Cannot instantiate abstract class 'Mapping' with abstract attribute '__iter__'
963+
bad = Mapping[str, str]() # E: Cannot instantiate abstract class "Mapping" with abstract attribute "__iter__"
964964
default = Config({'cannot': 'modify'}) # OK
965965

966966
default[1] = 2 # E: Unsupported target for indexed assignment ("Config")
@@ -1008,9 +1008,9 @@ a.do()
10081008
b = my_concrete_types['B']()
10091009
b.do()
10101010

1011-
c = my_abstract_types['A']() # E: Cannot instantiate abstract class 'MyAbstractType' with abstract attribute 'do'
1011+
c = my_abstract_types['A']() # E: Cannot instantiate abstract class "MyAbstractType" with abstract attribute "do"
10121012
c.do()
1013-
d = my_abstract_types['B']() # E: Cannot instantiate abstract class 'MyAbstractType' with abstract attribute 'do'
1013+
d = my_abstract_types['B']() # E: Cannot instantiate abstract class "MyAbstractType" with abstract attribute "do"
10141014
d.do()
10151015

10161016
[builtins fixtures/dict.pyi]

test-data/unit/check-annotated.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ reveal_type(x) # N: Revealed type is "builtins.int"
2525

2626
[case testAnnotatedBadType]
2727
from typing_extensions import Annotated
28-
x: Annotated[XXX, ...] # E: Name 'XXX' is not defined
28+
x: Annotated[XXX, ...] # E: Name "XXX" is not defined
2929
reveal_type(x) # N: Revealed type is "Any"
3030
[builtins fixtures/tuple.pyi]
3131

@@ -56,7 +56,7 @@ reveal_type(x) # N: Revealed type is "Union[builtins.int, builtins.str]"
5656

5757
[case testAnnotatedNestedBadType]
5858
from typing_extensions import Annotated
59-
x: Annotated[Annotated[XXX, ...], ...] # E: Name 'XXX' is not defined
59+
x: Annotated[Annotated[XXX, ...], ...] # E: Name "XXX" is not defined
6060
reveal_type(x) # N: Revealed type is "Any"
6161
[builtins fixtures/tuple.pyi]
6262

@@ -73,7 +73,7 @@ reveal_type(x) # N: Revealed type is "Any"
7373
[builtins fixtures/tuple.pyi]
7474

7575
[case testAnnotatedNoImport]
76-
x: Annotated[int, ...] # E: Name 'Annotated' is not defined
76+
x: Annotated[int, ...] # E: Name "Annotated" is not defined
7777
reveal_type(x) # N: Revealed type is "Any"
7878

7979
[case testAnnotatedDifferentName]

test-data/unit/check-attr.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ import attr
12951295

12961296
@attr.s
12971297
class C:
1298-
total = attr.ib(type=Bad) # E: Name 'Bad' is not defined
1298+
total = attr.ib(type=Bad) # E: Name "Bad" is not defined
12991299
[builtins fixtures/bool.pyi]
13001300

13011301
[case testTypeInAttrForwardInRuntime]
@@ -1329,7 +1329,7 @@ import attr
13291329

13301330
@attr.s(frozen=True)
13311331
class C:
1332-
total = attr.ib(type=Bad) # E: Name 'Bad' is not defined
1332+
total = attr.ib(type=Bad) # E: Name "Bad" is not defined
13331333

13341334
C(0).total = 1 # E: Property "total" defined in "C" is read-only
13351335
[builtins fixtures/bool.pyi]

test-data/unit/check-classes.test

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class D(object):
235235
class A(object):
236236
def f(self) -> None:
237237
self.attr = 1
238-
attr # E: Name 'attr' is not defined
238+
attr # E: Name "attr" is not defined
239239

240240
class B(object):
241241
attr = 0
@@ -2918,7 +2918,7 @@ C(arg=0)
29182918

29192919
[case testErrorMapToSupertype]
29202920
import typing
2921-
class X(Nope): pass # E: Name 'Nope' is not defined
2921+
class X(Nope): pass # E: Name "Nope" is not defined
29222922
a, b = X() # Used to crash here (#2244)
29232923

29242924

@@ -5239,7 +5239,7 @@ b = object()
52395239
@b.nothing # E: "object" has no attribute "nothing"
52405240
class C: pass
52415241

5242-
@undefined # E: Name 'undefined' is not defined
5242+
@undefined # E: Name "undefined" is not defined
52435243
class D: pass
52445244

52455245
[case testSlotsCompatibility]
@@ -6120,9 +6120,9 @@ class B(A):
61206120
class C(B):
61216121
def __init__(self, a: int) -> None:
61226122
self.c = a
6123-
a = A(1) # E: Cannot instantiate abstract class 'A' with abstract attribute '__init__'
6123+
a = A(1) # E: Cannot instantiate abstract class "A" with abstract attribute "__init__"
61246124
A.c # E: "Type[A]" has no attribute "c"
6125-
b = B(2) # E: Cannot instantiate abstract class 'B' with abstract attribute '__init__'
6125+
b = B(2) # E: Cannot instantiate abstract class "B" with abstract attribute "__init__"
61266126
B.c # E: "Type[B]" has no attribute "c"
61276127
c = C(3)
61286128
c.c
@@ -6619,7 +6619,7 @@ reveal_type(Foo().y) # N: Revealed type is "builtins.list[Any]"
66196619

66206620
class Foo:
66216621
def bad(): # E: Method must have at least one argument
6622-
self.x = 0 # E: Name 'self' is not defined
6622+
self.x = 0 # E: Name "self" is not defined
66236623

66246624
[case testTypeAfterAttributeAccessWithDisallowAnyExpr]
66256625
# flags: --disallow-any-expr

test-data/unit/check-columns.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ if int():
196196
pass
197197

198198
[case testColumnNameIsNotDefined]
199-
((x)) # E:3: Name 'x' is not defined
199+
((x)) # E:3: Name "x" is not defined
200200

201201
[case testColumnNeedTypeAnnotation]
202202
if 1:

test-data/unit/check-dataclasses.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,8 @@ from dataclasses import dataclass
881881

882882
@dataclass
883883
class B:
884-
x: Undefined # E: Name 'Undefined' is not defined
885-
y = undefined() # E: Name 'undefined' is not defined
884+
x: Undefined # E: Name "Undefined" is not defined
885+
y = undefined() # E: Name "undefined" is not defined
886886

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

test-data/unit/check-enum.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ main:2: error: Too few arguments for Enum()
425425
main:3: error: Enum() expects a string, tuple, list or dict literal as the second argument
426426
main:4: error: Too many arguments for Enum()
427427
main:5: error: Enum() expects a string, tuple, list or dict literal as the second argument
428-
main:5: error: Name 'foo' is not defined
428+
main:5: error: Name "foo" is not defined
429429
main:7: error: Enum() expects a string, tuple, list or dict literal as the second argument
430430
main:8: error: Too few arguments for IntEnum()
431431
main:9: error: IntEnum() expects a string, tuple, list or dict literal as the second argument

0 commit comments

Comments
 (0)