Skip to content

Use double quotes errors in 'dont mix' and 'has no attributes' #10296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/source/class_basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ initialized within the class. Mypy infers the types of attributes:

a = A(1)
a.x = 2 # OK!
a.y = 3 # Error: 'A' has no attribute 'y'
a.y = 3 # Error: "A" has no attribute "y"

This is a bit like each class having an implicitly defined
:py:data:`__slots__ <object.__slots__>` attribute. This is only enforced during type
Expand Down
2 changes: 1 addition & 1 deletion docs/source/error_code_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ target module can be found):

.. code-block:: python

# Error: Module 'os' has no attribute 'non_existent' [attr-defined]
# Error: Module "os" has no attribute "non_existent" [attr-defined]
from os import non_existent

A reference to a missing attribute is given the ``Any`` type. In the
Expand Down
4 changes: 2 additions & 2 deletions mypy/plugins/attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _determine_eq_order(ctx: 'mypy.plugin.ClassDefContext') -> bool:
order = _get_decorator_optional_bool_argument(ctx, 'order')

if cmp is not None and any((eq is not None, order is not None)):
ctx.api.fail("Don't mix `cmp` with `eq' and `order`", ctx.reason)
ctx.api.fail('Don\'t mix "cmp" with "eq" and "order"', ctx.reason)

# cmp takes precedence due to bw-compatibility.
if cmp is not None:
Expand All @@ -226,7 +226,7 @@ def _determine_eq_order(ctx: 'mypy.plugin.ClassDefContext') -> bool:
order = eq

if eq is False and order is True:
ctx.api.fail("eq must be True if order is True", ctx.reason)
ctx.api.fail('eq must be True if order is True', ctx.reason)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could undo this quote change but I don't feel strongly


return order

Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1856,7 +1856,7 @@ def report_missing_module_attribute(
# is incomplete. Defer the current target.
self.mark_incomplete(imported_id, context)
return
message = "Module '{}' has no attribute '{}'".format(import_id, source_id)
message = 'Module "{}" has no attribute "{}"'.format(import_id, source_id)
# Suggest alternatives, if any match is found.
module = self.modules.get(import_id)
if module:
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-attr.test
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class DeprecatedTrue:
class DeprecatedFalse:
...

@attrs(cmp=False, eq=True) # E: Don't mix `cmp` with `eq' and `order`
@attrs(cmp=False, eq=True) # E: Don't mix "cmp" with "eq" and "order"
class Mixed:
...

Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-columns.test
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def f(x: object, n: int, s: str) -> None:
[case testColumnHasNoAttribute]
import m
if int():
from m import foobaz # E:5: Module 'm' has no attribute 'foobaz'; maybe "foobar"?
from m import foobaz # E:5: Module "m" has no attribute "foobaz"; maybe "foobar"?
1 .x # E:1: "int" has no attribute "x"
(m.foobaz()) # E:2: Module has no attribute "foobaz"; maybe "foobar"?

Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import m
m.x # E: Module has no attribute "x" [attr-defined]
'x'.foobar # E: "str" has no attribute "foobar" [attr-defined]
from m import xx # E: Module 'm' has no attribute 'xx' [attr-defined]
from m import think # E: Module 'm' has no attribute 'think'; maybe "thing"? [attr-defined]
from m import xx # E: Module "m" has no attribute "xx" [attr-defined]
from m import think # E: Module "m" has no attribute "think"; maybe "thing"? [attr-defined]
for x in 1: # E: "int" has no attribute "__iter__" (not iterable) [attr-defined]
pass
[file m.py]
Expand Down Expand Up @@ -504,7 +504,7 @@ from defusedxml import xyz # E: Cannot find implementation or library stub for
from nonexistent import foobar # E: Cannot find implementation or library stub for module named "nonexistent" [import]
import nonexistent2 # E: Cannot find implementation or library stub for module named "nonexistent2" [import]
from nonexistent3 import * # E: Cannot find implementation or library stub for module named "nonexistent3" [import]
from pkg import bad # E: Module 'pkg' has no attribute 'bad' [attr-defined]
from pkg import bad # E: Module "pkg" has no attribute "bad" [attr-defined]
from pkg.bad2 import bad3 # E: Cannot find implementation or library stub for module named "pkg.bad2" [import]
[file pkg/__init__.py]

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 @@ -1303,7 +1303,7 @@ implicit_reexport = True
\[mypy-other_module_2]
implicit_reexport = False
[out]
main:2: error: Module 'other_module_2' has no attribute 'a'
main:2: error: Module "other_module_2" has no attribute "a"

[case testImplicitAnyOKForNoArgs]
# flags: --disallow-any-generics --show-column-numbers
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-incomplete-fixture.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ m.x # E: "object" has no attribute "x"
from typing import List
def f(x: List[int]) -> None: pass
[out]
main:1: error: Module 'typing' has no attribute 'List'
main:1: error: Module "typing" has no attribute "List"
main:1: note: Maybe your test fixture does not define "builtins.list"?
main:1: note: Consider adding [builtins fixtures/list.pyi] to your test description

[case testDictMissingFromStubs]
from typing import Dict
def f(x: Dict[int]) -> None: pass
[out]
main:1: error: Module 'typing' has no attribute 'Dict'
main:1: error: Module "typing" has no attribute "Dict"
main:1: note: Maybe your test fixture does not define "builtins.dict"?
main:1: note: Consider adding [builtins fixtures/dict.pyi] to your test description

[case testSetMissingFromStubs]
from typing import Set
def f(x: Set[int]) -> None: pass
[out]
main:1: error: Module 'typing' has no attribute 'Set'
main:1: error: Module "typing" has no attribute "Set"
main:1: note: Maybe your test fixture does not define "builtins.set"?
main:1: note: Consider adding [builtins fixtures/set.pyi] to your test description

Expand Down
40 changes: 20 additions & 20 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -1821,9 +1821,9 @@ class C:
A = NamedTuple('A', [('x', int), ('y', int)])
[builtins fixtures/tuple.pyi]
[out1]
main:1: error: Module 'ntcrash' has no attribute 'nope'
main:1: error: Module "ntcrash" has no attribute "nope"
[out2]
main:1: error: Module 'ntcrash' has no attribute 'nope'
main:1: error: Module "ntcrash" has no attribute "nope"

[case testIncrementalNamedTupleInMethod2]
from ntcrash import nope
Expand All @@ -1835,9 +1835,9 @@ class C:
A = NamedTuple('A', [('x', int), ('y', int)])
[builtins fixtures/tuple.pyi]
[out1]
main:1: error: Module 'ntcrash' has no attribute 'nope'
main:1: error: Module "ntcrash" has no attribute "nope"
[out2]
main:1: error: Module 'ntcrash' has no attribute 'nope'
main:1: error: Module "ntcrash" has no attribute "nope"

[case testIncrementalNamedTupleInMethod3]
from ntcrash import nope
Expand All @@ -1850,9 +1850,9 @@ class C:
A = NamedTuple('A', [('x', int), ('y', int)])
[builtins fixtures/tuple.pyi]
[out1]
main:1: error: Module 'ntcrash' has no attribute 'nope'
main:1: error: Module "ntcrash" has no attribute "nope"
[out2]
main:1: error: Module 'ntcrash' has no attribute 'nope'
main:1: error: Module "ntcrash" has no attribute "nope"

[case testIncrementalTypedDictInMethod]
from tdcrash import nope
Expand All @@ -1863,9 +1863,9 @@ class C:
A = TypedDict('A', {'x': int, 'y': int})
[builtins fixtures/dict.pyi]
[out1]
main:1: error: Module 'tdcrash' has no attribute 'nope'
main:1: error: Module "tdcrash" has no attribute "nope"
[out2]
main:1: error: Module 'tdcrash' has no attribute 'nope'
main:1: error: Module "tdcrash" has no attribute "nope"

[case testIncrementalTypedDictInMethod2]
from tdcrash import nope
Expand All @@ -1877,9 +1877,9 @@ class C:
A = TypedDict('A', {'x': int, 'y': int})
[builtins fixtures/dict.pyi]
[out1]
main:1: error: Module 'tdcrash' has no attribute 'nope'
main:1: error: Module "tdcrash" has no attribute "nope"
[out2]
main:1: error: Module 'tdcrash' has no attribute 'nope'
main:1: error: Module "tdcrash" has no attribute "nope"

[case testIncrementalTypedDictInMethod3]
from tdcrash import nope
Expand All @@ -1892,9 +1892,9 @@ class C:
A = TypedDict('A', {'x': int, 'y': int})
[builtins fixtures/dict.pyi]
[out1]
main:1: error: Module 'tdcrash' has no attribute 'nope'
main:1: error: Module "tdcrash" has no attribute "nope"
[out2]
main:1: error: Module 'tdcrash' has no attribute 'nope'
main:1: error: Module "tdcrash" has no attribute "nope"

[case testIncrementalNewTypeInMethod]
from ntcrash import nope
Expand All @@ -1914,9 +1914,9 @@ def f() -> None:

[builtins fixtures/dict.pyi]
[out1]
main:1: error: Module 'ntcrash' has no attribute 'nope'
main:1: error: Module "ntcrash" has no attribute "nope"
[out2]
main:1: error: Module 'ntcrash' has no attribute 'nope'
main:1: error: Module "ntcrash" has no attribute "nope"

[case testIncrementalInnerClassAttrInMethod]
import crash
Expand Down Expand Up @@ -2225,9 +2225,9 @@ from b import x
1 + 1
[out]
[out2]
tmp/b.py:1: error: Module 'c' has no attribute 'x'
tmp/b.py:1: error: Module "c" has no attribute "x"
[out3]
tmp/b.py:1: error: Module 'c' has no attribute 'x'
tmp/b.py:1: error: Module "c" has no attribute "x"

[case testCacheDeletedAfterErrorsFound2]

Expand Down Expand Up @@ -2284,9 +2284,9 @@ from b import x
1 + 1
[out]
[out2]
tmp/c.py:1: error: Module 'd' has no attribute 'x'
tmp/c.py:1: error: Module "d" has no attribute "x"
[out3]
tmp/c.py:1: error: Module 'd' has no attribute 'x'
tmp/c.py:1: error: Module "d" has no attribute "x"

[case testNoCrashOnDeletedWithCacheOnCmdline]
# cmd: mypy -m nonexistent
Expand Down Expand Up @@ -4572,10 +4572,10 @@ B = List[A]

[builtins fixtures/list.pyi]
[out]
tmp/lib.pyi:4: error: Module 'other' has no attribute 'B'
tmp/lib.pyi:4: error: Module "other" has no attribute "B"
tmp/other.pyi:3: error: Cannot resolve name "B" (possible cyclic definition)
[out2]
tmp/lib.pyi:4: error: Module 'other' has no attribute 'B'
tmp/lib.pyi:4: error: Module "other" has no attribute "B"
tmp/other.pyi:3: error: Cannot resolve name "B" (possible cyclic definition)
tmp/a.py:3: note: Revealed type is "builtins.list[Any]"

Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-modules-case.test
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-- Type checker test cases dealing with modules and imports on case-insensitive filesystems.

[case testCaseSensitivityDir]
from a import B # E: Module 'a' has no attribute 'B'
from a import B # E: Module "a" has no attribute "B"

[file a/__init__.py]
[file a/b/__init__.py]

[case testCaseInsensitivityDir]
# flags: --config-file tmp/mypy.ini

from a import B # E: Module 'a' has no attribute 'B'
from a import B # E: Module "a" has no attribute "B"
from other import x
reveal_type(x) # N: Revealed type is "builtins.int"

Expand Down
18 changes: 9 additions & 9 deletions test-data/unit/check-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ from foo import B
class C(B):
pass
[out]
tmp/bar.py:1: error: Module 'foo' has no attribute 'B'
tmp/bar.py:1: error: Module "foo" has no attribute "B"

[case testImportSuppressedWhileAlmostSilent]
# cmd: mypy -m main
Expand Down Expand Up @@ -1817,8 +1817,8 @@ m = n # E: Cannot assign multiple modules to name 'm' without explicit 'types.M
[builtins fixtures/module.pyi]

[case testNoReExportFromStubs]
from stub import Iterable # E: Module 'stub' has no attribute 'Iterable'
from stub import D # E: Module 'stub' has no attribute 'D'
from stub import Iterable # E: Module "stub" has no attribute "Iterable"
from stub import D # E: Module "stub" has no attribute "D"
from stub import C

c = C()
Expand Down Expand Up @@ -1912,7 +1912,7 @@ class C:

[case testNoReExportChildStubs]
import mod
from mod import C, D # E: Module 'mod' has no attribute 'C'
from mod import C, D # E: Module "mod" has no attribute "C"

reveal_type(mod.x) # N: Revealed type is "mod.submod.C"
mod.C # E: Module has no attribute "C"
Expand All @@ -1930,7 +1930,7 @@ class D:
[builtins fixtures/module.pyi]

[case testNoReExportNestedStub]
from stub import substub # E: Module 'stub' has no attribute 'substub'
from stub import substub # E: Module "stub" has no attribute "substub"

[file stub.pyi]
import substub
Expand Down Expand Up @@ -2074,7 +2074,7 @@ def __getattr__(name: str) -> int: ...

[case testModuleLevelGetattrImportFromNotStub36]
# flags: --python-version 3.6
from non_stub import name # E: Module 'non_stub' has no attribute 'name'
from non_stub import name # E: Module "non_stub" has no attribute "name"
reveal_type(name) # N: Revealed type is "Any"

[file non_stub.py]
Expand Down Expand Up @@ -2814,10 +2814,10 @@ CustomDict = TypedDict(
[builtins fixtures/tuple.pyi]

[case testNoReExportFromMissingStubs]
from stub import a # E: Module 'stub' has no attribute 'a'
from stub import a # E: Module "stub" has no attribute "a"
from stub import b
from stub import c # E: Module 'stub' has no attribute 'c'
from stub import d # E: Module 'stub' has no attribute 'd'
from stub import c # E: Module "stub" has no attribute "c"
from stub import d # E: Module "stub" has no attribute "d"

[file stub.pyi]
from mystery import a, b as b, c as d
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-newsemanal.test
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ tmp/a.py:4: error: "B" not callable
[case testNewAnalyzerTypeAnnotationCycle3]
import b
[file a.py]
from b import bad # E: Module 'b' has no attribute 'bad'; maybe "bad2"?
from b import bad # E: Module "b" has no attribute "bad"; maybe "bad2"?
[file b.py]
from a import bad2 # E: Module 'a' has no attribute 'bad2'; maybe "bad"?
from a import bad2 # E: Module "a" has no attribute "bad2"; maybe "bad"?

[case testNewAnalyzerTypeAnnotationCycle4]
import b
[file a.py]
from b import bad # E: Module 'b' has no attribute 'bad'
from b import bad # E: Module "b" has no attribute "bad"
[file b.py]
# TODO: Could we generate an error here as well?
from a import bad
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fine-grained-blockers.test
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class A:
main:1: error: Cannot find implementation or library stub for module named "a"
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
==
main:1: error: Module 'a' has no attribute 'A'
main:1: error: Module "a" has no attribute "A"

[case testFixingBlockingErrorBringsInAnotherModuleWithBlocker]
import a
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fine-grained-cycles.test
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def h() -> None:

[out]
==
a.py:1: error: Module 'b' has no attribute 'C'
a.py:1: error: Module "b" has no attribute "C"

[case testReferenceToTypeThroughCycleAndReplaceWithFunction]

Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fine-grained-follow-imports.test
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ from p import m
main.py:1: error: Cannot find implementation or library stub for module named "p"
main.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
==
main.py:1: error: Module 'p' has no attribute 'm'
main.py:1: error: Module "p" has no attribute "m"
==
p/m.py:1: error: "str" not callable

Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/fine-grained-modules.test
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ from p import q
[file p/q.py.3]
[out]
==
main:1: error: Module 'p' has no attribute 'q'
main:1: error: Module "p" has no attribute "q"
-- TODO: The following messages are different compared to non-incremental mode
main:1: error: Cannot find implementation or library stub for module named "p.q"
main:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Expand Down Expand Up @@ -1474,7 +1474,7 @@ from c import *
[file c.py.2]
def f(x: int) -> None: pass
[out]
main:1: error: Module 'b' has no attribute 'f'
main:1: error: Module "b" has no attribute "f"
==
main:2: error: Missing positional argument "x" in call to "f"

Expand Down Expand Up @@ -1523,7 +1523,7 @@ from p.c import *
[file p/c.py.2]
def f(x: int) -> None: pass
[out]
main:1: error: Module 'p.b' has no attribute 'f'
main:1: error: Module "p.b" has no attribute "f"
==
main:2: error: Missing positional argument "x" in call to "f"

Expand Down Expand Up @@ -1551,7 +1551,7 @@ def f() -> None: pass
[file c.py.2]
[out]
==
main:1: error: Module 'b' has no attribute 'f'
main:1: error: Module "b" has no attribute "f"

[case testImportStarRemoveDependency2]
from b import *
Expand Down
Loading