Skip to content

Commit

Permalink
In error messages, quote just the module's name (#14567)
Browse files Browse the repository at this point in the history
  • Loading branch information
ikonst authored Jan 31, 2023
1 parent 1a781e7 commit 90168b8
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -2209,6 +2209,7 @@ def quote_type_string(type_string: str) -> str:
no_quote_regex = r"^<(tuple|union): \d+ items>$"
if (
type_string in ["Module", "overloaded function", "<nothing>", "<deleted>"]
or type_string.startswith("Module ")
or re.match(no_quote_regex, type_string) is not None
or type_string.endswith("?")
):
Expand Down Expand Up @@ -2285,7 +2286,7 @@ def format_literal_value(typ: LiteralType) -> str:
# Make some common error messages simpler and tidier.
base_str = "Module"
if itype.extra_attrs and itype.extra_attrs.mod_name and module_names:
return f"{base_str} {itype.extra_attrs.mod_name}"
return f'{base_str} "{itype.extra_attrs.mod_name}"'
return base_str
if itype.type.fullname == "typing._SpecialForm":
# This is not a real type but used for some typing-related constructs.
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -6054,7 +6054,7 @@ def update() -> str: ...
[out]
[out2]
tmp/m.py:9: error: Argument 1 to "setup" has incompatible type Module; expected "Options"
tmp/m.py:9: note: Following member(s) of "Module default_config" have conflicts:
tmp/m.py:9: note: Following member(s) of Module "default_config" have conflicts:
tmp/m.py:9: note: Expected:
tmp/m.py:9: note: def update() -> bool
tmp/m.py:9: note: Got:
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 @@ -1852,7 +1852,7 @@ class C:
import stub

reveal_type(stub.y) # N: Revealed type is "builtins.int"
reveal_type(stub.z) # E: "Module stub" does not explicitly export attribute "z" \
reveal_type(stub.z) # E: Module "stub" does not explicitly export attribute "z" \
# N: Revealed type is "Any"

[file stub.pyi]
Expand Down Expand Up @@ -1944,7 +1944,7 @@ import mod
from mod import C, D # E: Module "mod" does not explicitly export attribute "C"

reveal_type(mod.x) # N: Revealed type is "mod.submod.C"
mod.C # E: "Module mod" does not explicitly export attribute "C"
mod.C # E: Module "mod" does not explicitly export attribute "C"
y = mod.D()
reveal_type(y.a) # N: Revealed type is "builtins.str"

Expand Down
8 changes: 4 additions & 4 deletions test-data/unit/check-protocols.test
Original file line number Diff line number Diff line change
Expand Up @@ -3720,10 +3720,10 @@ setup(bad_config_1) # E: Argument 1 to "setup" has incompatible type Module; ex
# N: "ModuleType" is missing following "Options" protocol member: \
# N: timeout
setup(bad_config_2) # E: Argument 1 to "setup" has incompatible type Module; expected "Options" \
# N: Following member(s) of "Module bad_config_2" have conflicts: \
# N: Following member(s) of Module "bad_config_2" have conflicts: \
# N: one_flag: expected "bool", got "int"
setup(bad_config_3) # E: Argument 1 to "setup" has incompatible type Module; expected "Options" \
# N: Following member(s) of "Module bad_config_3" have conflicts: \
# N: Following member(s) of Module "bad_config_3" have conflicts: \
# N: Expected: \
# N: def update() -> bool \
# N: Got: \
Expand Down Expand Up @@ -3789,7 +3789,7 @@ class Result(Protocol):
def run(x: Runner) -> None: ...
run(runner) # OK
run(bad_runner) # E: Argument 1 to "run" has incompatible type Module; expected "Runner" \
# N: Following member(s) of "Module bad_runner" have conflicts: \
# N: Following member(s) of Module "bad_runner" have conflicts: \
# N: Expected: \
# N: def (int, /) -> Result \
# N: Got: \
Expand Down Expand Up @@ -3821,7 +3821,7 @@ class Result(Protocol):
def run(x: Runner) -> None: ...
run(runner) # OK
run(bad_runner) # E: Argument 1 to "run" has incompatible type Module; expected "Runner" \
# N: Following member(s) of "Module bad_runner" have conflicts: \
# N: Following member(s) of Module "bad_runner" have conflicts: \
# N: Expected: \
# N: def (int, /) -> Result \
# N: Got: \
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -9975,7 +9975,7 @@ def update() -> str: ...
[out]
==
m.py:9: error: Argument 1 to "setup" has incompatible type Module; expected "Options"
m.py:9: note: Following member(s) of "Module default_config" have conflicts:
m.py:9: note: Following member(s) of Module "default_config" have conflicts:
m.py:9: note: Expected:
m.py:9: note: def update() -> bool
m.py:9: note: Got:
Expand Down

0 comments on commit 90168b8

Please sign in to comment.