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]

0 commit comments

Comments
 (0)