https://github.com/python/cpython/commit/aed613fe2fc85e4c537b34ce538647938f0b28e3
commit: aed613fe2fc85e4c537b34ce538647938f0b28e3
branch: 3.13
author: sobolevn <m...@sobolevn.me>
committer: sobolevn <m...@sobolevn.me>
date: 2025-05-08T06:59:04Z
summary:

[3.13] gh-133403: Type `Tools/build/update_file.py` and check it with `mypy` 
(GH-133404) (#133637)

(cherry picked from commit 50b52cba2d13a1854bc835412ac3f3c0ad42b5ba)

files:
M Tools/build/mypy.ini
M Tools/build/update_file.py

diff --git a/Tools/build/mypy.ini b/Tools/build/mypy.ini
index 0e5d6e874a72e5..db546c6fb3481c 100644
--- a/Tools/build/mypy.ini
+++ b/Tools/build/mypy.ini
@@ -1,5 +1,9 @@
 [mypy]
-files = Tools/build/generate_sbom.py
+files =
+    Tools/build/compute-changes.py,
+    Tools/build/generate_sbom.py,
+    Tools/build/update_file.py
+
 pretty = True
 
 # Make sure Python can still be built
@@ -8,6 +12,8 @@ python_version = 3.10
 
 # ...And be strict:
 strict = True
+strict_bytes = True
+local_partial_types = True
 extra_checks = True
 enable_error_code = 
ignore-without-code,redundant-expr,truthy-bool,possibly-undefined
 warn_unreachable = True
diff --git a/Tools/build/update_file.py b/Tools/build/update_file.py
index b4182c1d0cb638..b4a5fb6e778ae8 100644
--- a/Tools/build/update_file.py
+++ b/Tools/build/update_file.py
@@ -6,14 +6,27 @@
 actually change the in-tree generated code.
 """
 
+from __future__ import annotations
+
 import contextlib
 import os
 import os.path
 import sys
 
+TYPE_CHECKING = False
+if TYPE_CHECKING:
+    import typing
+    from collections.abc import Iterator
+    from io import TextIOWrapper
+
+    _Outcome: typing.TypeAlias = typing.Literal['created', 'updated', 'same']
+
 
 @contextlib.contextmanager
-def updating_file_with_tmpfile(filename, tmpfile=None):
+def updating_file_with_tmpfile(
+    filename: str,
+    tmpfile: str | None = None,
+) -> Iterator[tuple[TextIOWrapper, TextIOWrapper]]:
     """A context manager for updating a file via a temp file.
 
     The context manager provides two open files: the source file open
@@ -46,13 +59,18 @@ def updating_file_with_tmpfile(filename, tmpfile=None):
     update_file_with_tmpfile(filename, tmpfile)
 
 
-def update_file_with_tmpfile(filename, tmpfile, *, create=False):
+def update_file_with_tmpfile(
+    filename: str,
+    tmpfile: str,
+    *,
+    create: bool = False,
+) -> _Outcome:
     try:
         targetfile = open(filename, 'rb')
     except FileNotFoundError:
         if not create:
             raise  # re-raise
-        outcome = 'created'
+        outcome: _Outcome = 'created'
         os.replace(tmpfile, filename)
     else:
         with targetfile:

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to