Skip to content

Commit

Permalink
Use double quotes in error messages (#10511)
Browse files Browse the repository at this point in the history
Changes the messages "Inconsistent use of * in function", "is a type variable and only valid in type context" and "Import of x ignored"
  • Loading branch information
dixith authored May 20, 2021
1 parent c3a600b commit eb6f092
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion docs/source/running_mypy.rst
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ accepts one of four string values:
- ``error`` behaves in the same way as ``skip`` but is not quite as
silent -- it will flag the import as an error, like this::

main.py:1: note: Import of 'mycode.bar' ignored
main.py:1: note: Import of "mycode.bar" ignored
main.py:1: note: (Using --follow-imports=error, module not passed on command line)

If you are starting a new codebase and plan on using type hints from
Expand Down
4 changes: 2 additions & 2 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2568,7 +2568,7 @@ def skipping_module(manager: BuildManager, line: int, caller_state: Optional[Sta
manager.errors.set_import_context(caller_state.import_context)
manager.errors.set_file(caller_state.xpath, caller_state.id)
manager.errors.report(line, 0,
"Import of '%s' ignored" % (id,),
'Import of "%s" ignored' % (id,),
severity='error')
manager.errors.report(line, 0,
"(Using --follow-imports=error, module not passed on command line)",
Expand All @@ -2584,7 +2584,7 @@ def skipping_ancestor(manager: BuildManager, id: str, path: str, ancestor_for: '
# so we'd need to cache the decision.
manager.errors.set_import_context([])
manager.errors.set_file(ancestor_for.xpath, ancestor_for.id)
manager.errors.report(-1, -1, "Ancestor package '%s' ignored" % (id,),
manager.errors.report(-1, -1, 'Ancestor package "%s" ignored' % (id,),
severity='error', only_once=True)
manager.errors.report(-1, -1,
"(Using --follow-imports=error, submodule passed on command line)",
Expand Down
4 changes: 2 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3542,8 +3542,8 @@ def visit_name_expr(self, expr: NameExpr) -> None:
def bind_name_expr(self, expr: NameExpr, sym: SymbolTableNode) -> None:
"""Bind name expression to a symbol table node."""
if isinstance(sym.node, TypeVarExpr) and self.tvar_scope.get_binding(sym):
self.fail("'{}' is a type variable and only valid in type "
"context".format(expr.name), expr)
self.fail('"{}" is a type variable and only valid in type '
'context'.format(expr.name), expr)
elif isinstance(sym.node, PlaceholderNode):
self.process_placeholder(expr.name, 'name', expr)
else:
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Add the test in this format anywhere in the file:
b: str = 5 # E: Incompatible types in assignment (expression has type "int", variable has type "str")

zzz: int
zzz: str # E: Name 'zzz' already defined
zzz: str # E: Name "zzz" already defined

- no code here is executed, just type checked
- optional `# flags: ` indicates which flags to use for this unit test
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-flags.test
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ x + ""
[file mod.py]
deliberate syntax error
[out]
main:2: error: Import of 'mod' ignored
main:2: error: Import of "mod" ignored
main:2: note: (Using --follow-imports=error, module not passed on command line)

[case testIgnoreMissingImportsFalse]
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -1789,10 +1789,10 @@ import a
[file a.py.2]
//
[out1]
main:2: error: Import of 'a' ignored
main:2: error: Import of "a" ignored
main:2: note: (Using --follow-imports=error, module not passed on command line)
[out2]
main:2: error: Import of 'a' ignored
main:2: error: Import of "a" ignored
main:2: note: (Using --follow-imports=error, module not passed on command line)

[case testIncrementalFollowImportsVariable]
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ import mod
[file mod.py]
[builtins fixtures/module.pyi]
[out]
tmp/main.py:1: error: Import of 'mod' ignored
tmp/main.py:1: error: Import of "mod" ignored
tmp/main.py:1: note: (Using --follow-imports=error, module not passed on command line)

[case testAncestorSuppressedWhileAlmostSilent]
Expand All @@ -1064,7 +1064,7 @@ tmp/main.py:1: note: (Using --follow-imports=error, module not passed on command
[file foo/__init__.py]
[builtins fixtures/module.pyi]
[out]
tmp/foo/bar.py: error: Ancestor package 'foo' ignored
tmp/foo/bar.py: error: Ancestor package "foo" ignored
tmp/foo/bar.py: note: (Using --follow-imports=error, submodule passed on command line)

[case testStubImportNonStubWhileSilent]
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ follow_imports = error
[file a.py]
/ # No error reported
[out]
main.py:1: error: Import of 'a' ignored
main.py:1: error: Import of "a" ignored
main.py:1: note: (Using --follow-imports=error, module not passed on command line)
main.py:2: note: Revealed type is "Any"
main.py:4: note: Revealed type is "Any"
Expand Down Expand Up @@ -451,7 +451,7 @@ bla bla
bla bla
[out]
normal.py:2: error: Unsupported operand types for + ("int" and "str")
main.py:4: error: Import of 'error' ignored
main.py:4: error: Import of "error" ignored
main.py:4: note: (Using --follow-imports=error, module not passed on command line)
main.py:5: note: Revealed type is "builtins.int"
main.py:6: note: Revealed type is "builtins.int"
Expand Down Expand Up @@ -832,7 +832,7 @@ follow_imports_for_stubs = True
import math
math.frobnicate()
[out]
main.py:1: error: Import of 'math' ignored
main.py:1: error: Import of "math" ignored
main.py:1: note: (Using --follow-imports=error, module not passed on command line)

[case testFollowImportStubs2]
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/daemon.test
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Daemon started
$ dmypy check foo.py bar.py
$ dmypy recheck
$ dmypy recheck --update foo.py --remove bar.py sir_not_appearing_in_this_film.py
foo.py:1: error: Import of 'bar' ignored
foo.py:1: error: Import of "bar" ignored
foo.py:1: note: (Using --follow-imports=error, module not passed on command line)
== Return code: 1
$ dmypy recheck --update bar.py
Expand Down
10 changes: 5 additions & 5 deletions test-data/unit/fine-grained-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -1828,10 +1828,10 @@ x = 1
[file c.py.2]
x = '2'
[out]
a.py:2: error: Import of 'b' ignored
a.py:2: error: Import of "b" ignored
a.py:2: note: (Using --follow-imports=error, module not passed on command line)
==
a.py:2: error: Import of 'b' ignored
a.py:2: error: Import of "b" ignored
a.py:2: note: (Using --follow-imports=error, module not passed on command line)

[case testErrorButDontIgnore2]
Expand All @@ -1848,7 +1848,7 @@ x = 1
x = '2'
[out]
==
a.py:2: error: Import of 'b' ignored
a.py:2: error: Import of "b" ignored
a.py:2: note: (Using --follow-imports=error, module not passed on command line)

-- TODO: This test fails because p.b does not depend on p (#4847)
Expand All @@ -1868,7 +1868,7 @@ x = 1
x = '2'
[out]
==
p/b.py: error: Ancestor package 'p' ignored
p/b.py: error: Ancestor package "p" ignored
p/b.py: note: (Using --follow-imports=error, submodule passed on command line)

[case testErrorButDontIgnore4]
Expand All @@ -1886,7 +1886,7 @@ x = 1
[delete z.py.2]
[out]
==
p/b.py: error: Ancestor package 'p' ignored
p/b.py: error: Ancestor package "p" ignored
p/b.py: note: (Using --follow-imports=error, submodule passed on command line)
p/b.py:1: error: Cannot find implementation or library stub for module named "z"
p/b.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Expand Down
10 changes: 5 additions & 5 deletions test-data/unit/parse-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ def f(x): # type: (*X) -> Y
def g(*x): # type: (X) -> Y
pass
[out]
file:1: error: Inconsistent use of '*' in function signature
file:3: error: Inconsistent use of '*' in function signature
file:1: error: Inconsistent use of "*" in function signature
file:3: error: Inconsistent use of "*" in function signature

[case testCommentFunctionAnnotationVarArgMispatch2-skip]
# see mypy issue #1997
Expand All @@ -268,10 +268,10 @@ def f(*x, **y): # type: (**X, *Y) -> Z
def g(*x, **y): # type: (*X, *Y) -> Z
pass
[out]
file:1: error: Inconsistent use of '*' in function signature
file:1: error: Inconsistent use of "*" in function signature
file:3: error: syntax error in type comment
file:3: error: Inconsistent use of '*' in function signature
file:3: error: Inconsistent use of '**' in function signature
file:3: error: Inconsistent use of "*" in function signature
file:3: error: Inconsistent use of "**" in function signature

[case testPrintStatementInPython35]
# flags: --python-version 3.5
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/semanal-errors.test
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,8 @@ class c(Generic[t]):
def f(self) -> None: x = t
def f(y: t): x = t
[out]
main:4: error: 't' is a type variable and only valid in type context
main:5: error: 't' is a type variable and only valid in type context
main:4: error: "t" is a type variable and only valid in type context
main:5: error: "t" is a type variable and only valid in type context

[case testMissingSelf]
import typing
Expand Down

0 comments on commit eb6f092

Please sign in to comment.