Skip to content

Commit 7104782

Browse files
committed
Merge remote-tracking branch 'upstream/master' into bugfix/gh-19454-ops-on-typevr
2 parents 30c0e32 + de6e742 commit 7104782

File tree

249 files changed

+4567
-2044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+4567
-2044
lines changed

.github/ISSUE_TEMPLATE/crash.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ labels: "crash"
1515

1616
**Traceback**
1717

18-
```
18+
```python-traceback
1919
(Insert traceback and other messages from mypy here -- use `--show-traceback`.)
2020
```
2121

@@ -25,6 +25,11 @@ labels: "crash"
2525
appreciated. We also very much appreciate it if you try to narrow the
2626
source down to a small stand-alone example.)
2727

28+
```python
29+
# Ideally, a small sample program that demonstrates the problem.
30+
# Or even better, a reproducible playground link https://mypy-play.net/ (use the "Gist" button)
31+
```
32+
2833
**Your Environment**
2934

3035
<!-- Include as many relevant details about the environment you experienced the bug in -->

.github/workflows/test.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ jobs:
3737
toxenv: py
3838
tox_extra_args: "-n 4"
3939
test_mypyc: true
40-
- name: Test suite with py39-windows-64
41-
python: '3.9'
42-
os: windows-latest
43-
toxenv: py39
44-
tox_extra_args: "-n 4"
4540
- name: Test suite with py310-ubuntu
4641
python: '3.10'
4742
os: ubuntu-24.04-arm
@@ -64,6 +59,11 @@ jobs:
6459
toxenv: py
6560
tox_extra_args: "-n 4"
6661
test_mypyc: true
62+
- name: Test suite with py313-windows-64
63+
python: '3.13'
64+
os: windows-latest
65+
toxenv: py
66+
tox_extra_args: "-n 4"
6767

6868
- name: Test suite with py314-dev-ubuntu
6969
python: '3.14-dev'

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ Related PRs:
170170
* Enable ANSI color codes for dmypy client in Windows (wyattscarpenter, PR [19088](https://github.com/python/mypy/pull/19088))
171171
* Extend special case for context-based type variable inference to unions in return position (Stanislav Terliakov, PR [18976](https://github.com/python/mypy/pull/18976))
172172

173+
### Mypy 1.17.1
174+
* Retain `None` as constraints bottom if no bottoms were provided (Stanislav Terliakov, PR [19485](https://github.com/python/mypy/pull/19485))
175+
* Fix "ignored exception in `hasattr`" in dmypy (Stanislav Terliakov, PR [19428](https://github.com/python/mypy/pull/19428))
176+
* Prevent a crash when InitVar is redefined with a method in a subclass (Stanislav Terliakov, PR [19453](https://github.com/python/mypy/pull/19453))
177+
173178
### Acknowledgements
174179

175180
Thanks to all mypy contributors who contributed to this release:

docs/source/command_line.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,14 @@ of the above sections.
812812
Note: the exact list of flags enabled by running :option:`--strict` may change
813813
over time.
814814

815+
.. include:: strict_list.rst
816+
..
817+
The above file is autogenerated and included during html generation.
818+
(That's an include directive, and this is a comment.)
819+
It would be fine to generate it at some other time instead,
820+
theoretically, but we already had a convenient hook during html gen.
821+
822+
815823
.. option:: --disable-error-code
816824

817825
This flag allows disabling one or multiple error codes globally.

docs/source/common_issues.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,14 @@ daemon <mypy_daemon>`, which can speed up incremental mypy runtimes by
218218
a factor of 10 or more. :ref:`Remote caching <remote-cache>` can
219219
make cold mypy runs several times faster.
220220

221+
Furthermore: as of `mypy 1.13 <https://mypy-lang.blogspot.com/2024/10/mypy-113-released.html>`_,
222+
mypy allows use of the orjson library for handling the cache instead of the stdlib json, for
223+
improved performance. You can ensure the presence of orjson using the faster-cache extra:
224+
225+
python3 -m pip install -U mypy[faster-cache]
226+
227+
Mypy may depend on orjson by default in the future.
228+
221229
Types of empty collections
222230
--------------------------
223231

@@ -505,11 +513,15 @@ to see the types of all local variables at once. Example:
505513
# b: builtins.str
506514
.. note::
507515

508-
``reveal_type`` and ``reveal_locals`` are only understood by mypy and
509-
don't exist in Python. If you try to run your program, you'll have to
510-
remove any ``reveal_type`` and ``reveal_locals`` calls before you can
511-
run your code. Both are always available and you don't need to import
512-
them.
516+
``reveal_type`` and ``reveal_locals`` are handled specially by mypy during
517+
type checking, and don't have to be defined or imported.
518+
519+
However, if you want to run your code,
520+
you'll have to remove any ``reveal_type`` and ``reveal_locals``
521+
calls from your program or else Python will give you an error at runtime.
522+
523+
Alternatively, you can import ``reveal_type`` from ``typing_extensions``
524+
or ``typing`` (on Python 3.11 and newer)
513525

514526
.. _silencing-linters:
515527

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,9 @@
278278
intersphinx_mapping = {
279279
"python": ("https://docs.python.org/3", None),
280280
"attrs": ("https://www.attrs.org/en/stable/", None),
281-
"cython": ("https://docs.cython.org/en/latest", None),
281+
"cython": ("https://cython.readthedocs.io/en/stable", None),
282282
"monkeytype": ("https://monkeytype.readthedocs.io/en/latest", None),
283-
"setuptools": ("https://setuptools.readthedocs.io/en/latest", None),
283+
"setuptools": ("https://setuptools.pypa.io/en/latest", None),
284284
}
285285

286286

docs/source/dynamic_typing.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
.. _dynamic-typing:
22

3-
43
Dynamically typed code
54
======================
65

@@ -94,6 +93,8 @@ third party libraries that mypy does not know about. This is particularly the ca
9493
when using the :option:`--ignore-missing-imports <mypy --ignore-missing-imports>`
9594
flag. See :ref:`fix-missing-imports` for more information about this.
9695

96+
.. _any-vs-object:
97+
9798
Any vs. object
9899
--------------
99100

docs/source/html_builder.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,37 @@
1111
from sphinx.builders.html import StandaloneHTMLBuilder
1212
from sphinx.environment import BuildEnvironment
1313

14+
from mypy.main import define_options
15+
1416

1517
class MypyHTMLBuilder(StandaloneHTMLBuilder):
18+
strict_file: Path
19+
1620
def __init__(self, app: Sphinx, env: BuildEnvironment) -> None:
1721
super().__init__(app, env)
1822
self._ref_to_doc = {}
23+
self.strict_file = Path(self.srcdir) / "strict_list.rst"
24+
self._add_strict_list()
1925

2026
def write_doc(self, docname: str, doctree: document) -> None:
2127
super().write_doc(docname, doctree)
2228
self._ref_to_doc.update({_id: docname for _id in doctree.ids})
2329

30+
def _add_strict_list(self) -> None:
31+
strict_flags: list[str]
32+
_, strict_flags, _ = define_options()
33+
strict_part = ", ".join(f":option:`{s} <mypy {s}>`" for s in strict_flags)
34+
if (
35+
not strict_part
36+
or strict_part.isspace()
37+
or len(strict_part) < 20
38+
or len(strict_part) > 2000
39+
):
40+
raise ValueError(f"{strict_part=}, which doesn't look right (by a simple heuristic).")
41+
self.strict_file.write_text(
42+
"For this version of mypy, the list of flags enabled by strict is: " + strict_part
43+
)
44+
2445
def _verify_error_codes(self) -> None:
2546
from mypy.errorcodes import error_codes
2647

@@ -55,6 +76,7 @@ def _write_ref_redirector(self) -> None:
5576
def finish(self) -> None:
5677
super().finish()
5778
self._write_ref_redirector()
79+
self.strict_file.unlink()
5880

5981

6082
def setup(app: Sphinx) -> dict[str, Any]:

docs/source/kinds_of_types.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ operations are permitted on the value, and the operations are only checked
4141
at runtime. You can use ``Any`` as an "escape hatch" when you can't use
4242
a more precise type for some reason.
4343

44+
This should not be confused with the
45+
:py:class:`object` type, which represents the set of all values.
46+
Unlike ``object``, ``Any`` introduces type unsafety — see
47+
:ref:`any-vs-object` for more.
48+
4449
``Any`` is compatible with every other type, and vice versa. You can freely
4550
assign a value of type ``Any`` to a variable with a more precise type:
4651

misc/log_trace_check.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
"""Compile mypy using mypyc with trace logging enabled, and collect a trace.
2+
3+
The trace log can be used to analyze low-level performance bottlenecks.
4+
5+
By default does a self check as the workload.
6+
7+
This works on all supported platforms, unlike some of our other performance tools.
8+
"""
9+
10+
from __future__ import annotations
11+
12+
import argparse
13+
import glob
14+
import os
15+
import shutil
16+
import subprocess
17+
import sys
18+
import time
19+
20+
from perf_compare import build_mypy, clone
21+
22+
# Generated files, including binaries, go under this directory to avoid overwriting user state.
23+
TARGET_DIR = "mypy.log_trace.tmpdir"
24+
25+
26+
def perform_type_check(target_dir: str, code: str | None) -> None:
27+
cache_dir = os.path.join(target_dir, ".mypy_cache")
28+
if os.path.exists(cache_dir):
29+
shutil.rmtree(cache_dir)
30+
args = []
31+
if code is None:
32+
args.extend(["--config-file", "mypy_self_check.ini"])
33+
for pat in "mypy/*.py", "mypy/*/*.py", "mypyc/*.py", "mypyc/test/*.py":
34+
args.extend(glob.glob(pat))
35+
else:
36+
args.extend(["-c", code])
37+
check_cmd = ["python", "-m", "mypy"] + args
38+
t0 = time.time()
39+
subprocess.run(check_cmd, cwd=target_dir, check=True)
40+
elapsed = time.time() - t0
41+
print(f"{elapsed:.2f}s elapsed")
42+
43+
44+
def main() -> None:
45+
parser = argparse.ArgumentParser(
46+
description="Compile mypy and collect a trace log while type checking (by default, self check)."
47+
)
48+
parser.add_argument(
49+
"--multi-file",
50+
action="store_true",
51+
help="compile mypy into one C file per module (to reduce RAM use during compilation)",
52+
)
53+
parser.add_argument(
54+
"--skip-compile", action="store_true", help="use compiled mypy from previous run"
55+
)
56+
parser.add_argument(
57+
"-c",
58+
metavar="CODE",
59+
default=None,
60+
type=str,
61+
help="type check Python code fragment instead of mypy self-check",
62+
)
63+
args = parser.parse_args()
64+
multi_file: bool = args.multi_file
65+
skip_compile: bool = args.skip_compile
66+
code: str | None = args.c
67+
68+
target_dir = TARGET_DIR
69+
70+
if not skip_compile:
71+
clone(target_dir, "HEAD")
72+
73+
print(f"Building mypy in {target_dir} with trace logging enabled...")
74+
build_mypy(target_dir, multi_file, log_trace=True, opt_level="0")
75+
elif not os.path.isdir(target_dir):
76+
sys.exit("error: Can't find compile mypy from previous run -- can't use --skip-compile")
77+
78+
perform_type_check(target_dir, code)
79+
80+
trace_fnam = os.path.join(target_dir, "mypyc_trace.txt")
81+
print(f"Generated event trace log in {trace_fnam}")
82+
83+
84+
if __name__ == "__main__":
85+
main()

0 commit comments

Comments
 (0)