Skip to content

Commit d5bf1b9

Browse files
committed
Update docstring; more consistent formatitng in blockers
1 parent 9ce401a commit d5bf1b9

7 files changed

Lines changed: 30 additions & 25 deletions

File tree

mypy/build.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -913,8 +913,8 @@ def __init__(
913913
continue
914914
path = self.find_module_cache.find_module(module, fast_path=True)
915915
if not isinstance(path, str):
916-
raise CompileError(
917-
[f"Failed to find builtin module {module}, perhaps typeshed is broken?"]
916+
build_error(
917+
f'Failed to find builtin module "{module}", perhaps typeshed is broken?'
918918
)
919919
if is_typeshed_file(options.abs_custom_typeshed_dir, path) or is_stub_package_file(
920920
path
@@ -923,7 +923,7 @@ def __init__(
923923

924924
raise CompileError(
925925
[
926-
f'mypy: "{os.path.relpath(path)}" shadows library module "{module}"',
926+
f'mypy: error: "{os.path.relpath(path)}" shadows library module "{module}"',
927927
f'note: A user-defined top-level module with name "{module}" is not supported',
928928
]
929929
)
@@ -1256,7 +1256,11 @@ def all_imported_modules_in_file(self, file: MypyFile) -> list[tuple[int, str, i
12561256
return res
12571257

12581258
def is_module(self, id: str) -> bool:
1259-
"""Is there a file in the file system corresponding to module id?"""
1259+
"""Does the given fullname refer to a module?
1260+
1261+
Note: this does not always verify that the module exists and relies on
1262+
previously executed logic in find_module_and_diagnose().
1263+
"""
12601264
if id in self.modules:
12611265
# Micro-optimization, if we already found it, it is definitely a module.
12621266
return True
@@ -3158,7 +3162,7 @@ def get_source(self) -> str:
31583162
assert ioerr.errno is not None
31593163
raise CompileError(
31603164
[
3161-
"mypy: error: cannot read file '{}': {}".format(
3165+
"mypy: error: Cannot read file '{}': {}".format(
31623166
self.path.replace(os.getcwd() + os.sep, ""),
31633167
os.strerror(ioerr.errno),
31643168
)
@@ -3167,9 +3171,9 @@ def get_source(self) -> str:
31673171
) from ioerr
31683172
except (UnicodeDecodeError, DecodeError) as decodeerr:
31693173
if self.path.endswith(".pyd"):
3170-
err = f"{self.path}: error: stubgen does not support .pyd files"
3174+
err = f"{self.path}: error: Stubgen does not support .pyd files"
31713175
else:
3172-
err = f"{self.path}: error: cannot decode file: {str(decodeerr)}"
3176+
err = f"{self.path}: error: Cannot decode file: {str(decodeerr)}"
31733177
raise CompileError([err], module_with_blocker=self.id) from decodeerr
31743178
elif self.path and self.manager.fscache.isdir(self.path):
31753179
source = ""
@@ -3791,7 +3795,7 @@ def find_module_and_diagnose(
37913795
# If we can't find a root source it's always fatal.
37923796
# TODO: This might hide non-fatal errors from
37933797
# root sources processed earlier.
3794-
raise CompileError([f"mypy: can't find module '{id}'"])
3798+
raise CompileError([f'mypy: error: Cannot find module "{id}"'])
37953799
else:
37963800
raise ModuleNotFound
37973801

@@ -3920,7 +3924,7 @@ def module_not_found(
39203924
)
39213925
if target == "builtins":
39223926
manager.error(
3923-
line, "Cannot find 'builtins' module. Typeshed appears broken!", blocker=True
3927+
line, 'Cannot find "builtins" module. Typeshed appears broken!', blocker=True
39243928
)
39253929
errors.raise_error()
39263930
else:

mypy/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,8 @@ def set_strict_flags() -> None:
15771577
reason = cache.find_module(p)
15781578
if reason is ModuleNotFoundReason.FOUND_WITHOUT_TYPE_HINTS:
15791579
fail(
1580-
f"Package '{p}' cannot be type checked due to missing py.typed marker. See https://mypy.readthedocs.io/en/stable/installed_packages.html for more details",
1580+
f"Package '{p}' cannot be type checked due to missing py.typed marker.\n"
1581+
"See https://mypy.readthedocs.io/en/stable/installed_packages.html for more details",
15811582
stderr,
15821583
options,
15831584
)
@@ -1698,7 +1699,7 @@ def read_types_packages_to_install(cache_dir: str, after_run: bool) -> list[str]
16981699
if not after_run:
16991700
sys.stderr.write(
17001701
"error: Can't determine which types to install with no files to check "
1701-
+ "(and no cache from previous mypy run)\n"
1702+
"(and no cache from previous mypy run)\n"
17021703
)
17031704
else:
17041705
sys.stderr.write(

test-data/unit/check-incremental.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2334,7 +2334,7 @@ tmp/c.py:1: error: Module "d" has no attribute "x"
23342334
[delete nonexistent.py.2]
23352335
[out]
23362336
[out2]
2337-
mypy: error: cannot read file 'tmp/nonexistent.py': No such file or directory
2337+
mypy: error: Cannot read file 'tmp/nonexistent.py': No such file or directory
23382338

23392339
[case testSerializeAbstractPropertyIncremental]
23402340
from abc import abstractmethod

test-data/unit/cmdline.test

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ sub.pkg contains __init__.py but is not a valid Python package name
117117
[file a.py]
118118
# coding: uft-8
119119
[out]
120-
a.py: error: cannot decode file: unknown encoding: uft-8
120+
a.py: error: Cannot decode file: unknown encoding: uft-8
121121
== Return code: 2
122122

123123
[case testCannotIgnoreDuplicateModule]
@@ -416,7 +416,7 @@ int_pow.py:11: note: Revealed type is "Any"
416416
[case testMissingFile]
417417
# cmd: mypy nope.py
418418
[out]
419-
mypy: error: cannot read file 'nope.py': No such file or directory
419+
mypy: error: Cannot read file 'nope.py': No such file or directory
420420
== Return code: 2
421421

422422
[case testModulesAndPackages]
@@ -630,7 +630,7 @@ c.py:1: error: Name "fail" is not defined
630630
\[mypy]
631631
files = config.py
632632
[out]
633-
mypy: error: cannot read file 'override.py': No such file or directory
633+
mypy: error: Cannot read file 'override.py': No such file or directory
634634
== Return code: 2
635635

636636
[case testErrorSummaryOnSuccess]
@@ -687,7 +687,7 @@ Found 2 errors in 2 files (checked 2 source files)
687687
[case testErrorSummaryOnBadUsage]
688688
# cmd: mypy --error-summary missing.py
689689
[out]
690-
mypy: error: cannot read file 'missing.py': No such file or directory
690+
mypy: error: Cannot read file 'missing.py': No such file or directory
691691
Found 1 error in 1 file (errors prevented further checking)
692692
== Return code: 2
693693

@@ -763,7 +763,7 @@ imp.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#miss
763763
[file a.pyd]
764764
# coding: uft-8
765765
[out]
766-
a.pyd: error: stubgen does not support .pyd files
766+
a.pyd: error: Stubgen does not support .pyd files
767767
== Return code: 2
768768

769769
[case testDuplicateModules]
@@ -1065,7 +1065,7 @@ except ValueError:
10651065
from typing import *
10661066
sys.path = path
10671067
[out]
1068-
mypy: "typing.py" shadows library module "typing"
1068+
mypy: error: "typing.py" shadows library module "typing"
10691069
note: A user-defined top-level module with name "typing" is not supported
10701070
== Return code: 2
10711071

@@ -1083,7 +1083,7 @@ note: A user-defined top-level module with name "typing" is not supported
10831083
[file dir/stdlib/collections/__init__.pyi]
10841084
[file dir/stdlib/VERSIONS]
10851085
[out]
1086-
Failed to find builtin module mypy_extensions, perhaps typeshed is broken?
1086+
mypy: error: Failed to find builtin module "mypy_extensions", perhaps typeshed is broken?
10871087
== Return code: 2
10881088

10891089
[case testCustomTypeshedDirFilePassedExplicitly]

test-data/unit/fine-grained-blockers.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ def f(x: int) -> None: ...
502502
def f(x: str) -> None: ...
503503
[out]
504504
==
505-
a.py: error: cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
505+
a.py: error: Cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
506506
==
507507
main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str"
508508

@@ -518,7 +518,7 @@ def f(x: int) -> None: ...
518518
def f(x: str) -> None: ...
519519
[out]
520520
==
521-
a.py: error: cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 17: ordinal not in range(128)
521+
a.py: error: Cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 17: ordinal not in range(128)
522522
==
523523
main:2: error: Argument 1 to "f" has incompatible type "int"; expected "str"
524524

@@ -532,6 +532,6 @@ a.f(1)
532532
[file a.py.2]
533533
def f(x: str) -> None: ...
534534
[out]
535-
a.py: error: cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
535+
a.py: error: Cannot decode file: 'ascii' codec can't decode byte 0xc3 in position 16: ordinal not in range(128)
536536
==
537537
main:3: error: Argument 1 to "f" has incompatible type "int"; expected "str"

test-data/unit/fine-grained.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6068,9 +6068,9 @@ a.py:1: error: "int" not callable
60686068
[file a.py.2]
60696069
1()
60706070
[out]
6071-
mypy: error: cannot read file 'tmp/nonexistent.py': No such file or directory
6071+
mypy: error: Cannot read file 'tmp/nonexistent.py': No such file or directory
60726072
==
6073-
mypy: error: cannot read file 'tmp/nonexistent.py': No such file or directory
6073+
mypy: error: Cannot read file 'tmp/nonexistent.py': No such file or directory
60746074

60756075
[case testNonExistentFileOnCommandLine2]
60766076
# cmd: mypy a.py

test-data/unit/pythoneval.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ async def foo() -> None:
15181518
x = 0
15191519
1 + ''
15201520
[out]
1521-
mypy: "tmp/typing.py" shadows library module "typing"
1521+
mypy: error: "tmp/typing.py" shadows library module "typing"
15221522
note: A user-defined top-level module with name "typing" is not supported
15231523

15241524

0 commit comments

Comments
 (0)