Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 67e2933

Browse filesBrowse files
authored
Merge branch 'master' into mypybot/sync-typeshed
2 parents 4c48c2b + 67855fa commit 67e2933
Copy full SHA for 67e2933

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

59 files changed

+896
-350
lines changed

‎docs/source/command_line.rst

Copy file name to clipboardExpand all lines: docs/source/command_line.rst
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,9 +448,10 @@ potentially problematic or redundant in some way.
448448
are when:
449449

450450
- The function has a ``None`` or ``Any`` return type
451-
- The function has an empty body or a body that is just
452-
ellipsis (``...``). Empty functions are often used for
453-
abstract methods.
451+
- The function has an empty body and is marked as an abstract method,
452+
is in a protocol class, or is in a stub file
453+
- The execution path can never return; for example, if an exception
454+
is always raised
454455

455456
Passing in :option:`--no-warn-no-return` will disable these error
456457
messages in all cases.

‎docs/source/running_mypy.rst

Copy file name to clipboardExpand all lines: docs/source/running_mypy.rst
+15-31Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -322,34 +322,27 @@ the library, you will get a message like this:
322322
main.py:1: note: Hint: "python3 -m pip install types-PyYAML"
323323
main.py:1: note: (or run "mypy --install-types" to install all missing stub packages)
324324
325-
You can resolve the issue by running the suggested pip command or
326-
commands. Alternatively, you can use :option:`--install-types <mypy
327-
--install-types>` to install all known missing stubs:
325+
You can resolve the issue by running the suggested pip commands.
326+
If you're running mypy in CI, you can ensure the presence of any stub packages
327+
you need the same as you would any other test dependency, e.g. by adding them to
328+
the appropriate ``requirements.txt`` file.
328329

329-
.. code-block:: text
330-
331-
mypy --install-types
332-
333-
This installs any stub packages that were suggested in the previous
334-
mypy run. You can also use your normal mypy command line with the
335-
extra :option:`--install-types <mypy --install-types>` option to
336-
install missing stubs at the end of the run (if any were found).
337-
338-
Use :option:`--install-types <mypy --install-types>` with
339-
:option:`--non-interactive <mypy --non-interactive>` to install all suggested
340-
stub packages without asking for confirmation, *and* type check your
341-
code, in a single command:
330+
Alternatively, add the :option:`--install-types <mypy --install-types>`
331+
to your mypy command to install all known missing stubs:
342332

343333
.. code-block:: text
344334
345-
mypy --install-types --non-interactive src/
335+
mypy --install-types
346336
347-
This can be useful in Continuous Integration jobs if you'd prefer not
348-
to manage stub packages manually. This is somewhat slower than
349-
explicitly installing stubs before running mypy, since it may type
350-
check your code twice -- the first time to find the missing stubs, and
337+
This is slower than explicitly installing stubs, since it effectively
338+
runs mypy twice -- the first time to find the missing stubs, and
351339
the second time to type check your code properly after mypy has
352-
installed the stubs.
340+
installed the stubs. It also can make controlling stub versions harder,
341+
resulting in less reproducible type checking.
342+
343+
By default, :option:`--install-types <mypy --install-types>` shows a confirmation prompt.
344+
Use :option:`--non-interactive <mypy --non-interactive>` to install all suggested
345+
stub packages without asking for confirmation *and* type check your code:
353346

354347
If you've already installed the relevant third-party libraries in an environment
355348
other than the one mypy is running in, you can use :option:`--python-executable
@@ -394,15 +387,6 @@ this error, try:
394387
you must run ``mypy ~/foo-project/src`` (or set the ``MYPYPATH`` to
395388
``~/foo-project/src``.
396389

397-
In some rare cases, you may get the "Cannot find implementation or library
398-
stub for module" error even when the module is installed in your system.
399-
This can happen when the module is both missing type hints and is installed
400-
on your system in an unconventional way.
401-
402-
In this case, follow the steps above on how to handle
403-
:ref:`missing type hints in third party libraries <missing-type-hints-for-third-party-library>`.
404-
405-
406390
.. _finding-imports:
407391

408392
How imports are found

‎misc/fix_annotate.py

Copy file name to clipboardExpand all lines: misc/fix_annotate.py
+4-5Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ def has_return_exprs(self, node):
213213
results = {}
214214
if self.return_expr.match(node, results):
215215
return True
216-
for child in node.children:
217-
if child.type not in (syms.funcdef, syms.classdef):
218-
if self.has_return_exprs(child):
219-
return True
220-
return False
216+
return any(
217+
child.type not in (syms.funcdef, syms.classdef) and self.has_return_exprs(child)
218+
for child in node.children
219+
)

‎misc/upload-pypi.py

Copy file name to clipboardExpand all lines: misc/upload-pypi.py
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ def is_whl_or_tar(name: str) -> bool:
2929
return name.endswith(".tar.gz") or name.endswith(".whl")
3030

3131

32+
def item_ok_for_pypi(name: str) -> bool:
33+
if not is_whl_or_tar(name):
34+
return False
35+
36+
if name.endswith(".tar.gz"):
37+
name = name[:-7]
38+
if name.endswith(".whl"):
39+
name = name[:-4]
40+
41+
if name.endswith("wasm32"):
42+
return False
43+
44+
return True
45+
46+
3247
def get_release_for_tag(tag: str) -> dict[str, Any]:
3348
with urlopen(f"{BASE}/{REPO}/releases/tags/{tag}") as f:
3449
data = json.load(f)
@@ -75,7 +90,7 @@ def check_sdist(dist: Path, version: str) -> None:
7590

7691

7792
def spot_check_dist(dist: Path, version: str) -> None:
78-
items = [item for item in dist.iterdir() if is_whl_or_tar(item.name)]
93+
items = [item for item in dist.iterdir() if item_ok_for_pypi(item.name)]
7994
assert len(items) > 10
8095
assert all(version in item.name for item in items)
8196
assert any(item.name.endswith("py3-none-any.whl") for item in items)
@@ -93,7 +108,7 @@ def tmp_twine() -> Iterator[Path]:
93108

94109
def upload_dist(dist: Path, dry_run: bool = True) -> None:
95110
with tmp_twine() as twine:
96-
files = [item for item in dist.iterdir() if is_whl_or_tar(item.name)]
111+
files = [item for item in dist.iterdir() if item_ok_for_pypi(item.name)]
97112
cmd: list[Any] = [twine, "upload"]
98113
cmd += files
99114
if dry_run:

‎mypy/build.py

Copy file name to clipboardExpand all lines: mypy/build.py
+16-14Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ def __init__(
19401940
raise
19411941
if follow_imports == "silent":
19421942
self.ignore_all = True
1943-
elif path and is_silent_import_module(manager, path):
1943+
elif path and is_silent_import_module(manager, path) and not root_source:
19441944
self.ignore_all = True
19451945
self.path = path
19461946
if path:
@@ -2629,7 +2629,7 @@ def find_module_and_diagnose(
26292629
else:
26302630
skipping_module(manager, caller_line, caller_state, id, result)
26312631
raise ModuleNotFound
2632-
if is_silent_import_module(manager, result):
2632+
if is_silent_import_module(manager, result) and not root_source:
26332633
follow_imports = "silent"
26342634
return (result, follow_imports)
26352635
else:
@@ -2728,11 +2728,8 @@ def in_partial_package(id: str, manager: BuildManager) -> bool:
27282728
else:
27292729
parent_mod = parent_st.tree
27302730
if parent_mod is not None:
2731-
if parent_mod.is_partial_stub_package:
2732-
return True
2733-
else:
2734-
# Bail out soon, complete subpackage found
2735-
return False
2731+
# Bail out soon, complete subpackage found
2732+
return parent_mod.is_partial_stub_package
27362733
id = parent
27372734
return False
27382735

@@ -3024,7 +3021,11 @@ def load_graph(
30243021
for bs in sources:
30253022
try:
30263023
st = State(
3027-
id=bs.module, path=bs.path, source=bs.text, manager=manager, root_source=True
3024+
id=bs.module,
3025+
path=bs.path,
3026+
source=bs.text,
3027+
manager=manager,
3028+
root_source=not bs.followed,
30283029
)
30293030
except ModuleNotFound:
30303031
continue
@@ -3576,9 +3577,10 @@ def record_missing_stub_packages(cache_dir: str, missing_stub_packages: set[str]
35763577

35773578

35783579
def is_silent_import_module(manager: BuildManager, path: str) -> bool:
3579-
if not manager.options.no_silence_site_packages:
3580-
for dir in manager.search_paths.package_path + manager.search_paths.typeshed_path:
3581-
if is_sub_path(path, dir):
3582-
# Silence errors in site-package dirs and typeshed
3583-
return True
3584-
return False
3580+
if manager.options.no_silence_site_packages:
3581+
return False
3582+
# Silence errors in site-package dirs and typeshed
3583+
return any(
3584+
is_sub_path(path, dir)
3585+
for dir in manager.search_paths.package_path + manager.search_paths.typeshed_path
3586+
)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.