Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitaed613f

Browse files
authored
[3.13]gh-133403: TypeTools/build/update_file.py and check it withmypy (GH-133404) (#133637)
(cherry picked from commit50b52cb)
1 parenta063d6c commitaed613f

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

‎Tools/build/mypy.ini

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
[mypy]
2-
files = Tools/build/generate_sbom.py
2+
files =
3+
Tools/build/compute-changes.py,
4+
Tools/build/generate_sbom.py,
5+
Tools/build/update_file.py
6+
37
pretty = True
48

59
# Make sure Python can still be built
@@ -8,6 +12,8 @@ python_version = 3.10
812

913
# ...And be strict:
1014
strict = True
15+
strict_bytes = True
16+
local_partial_types = True
1117
extra_checks = True
1218
enable_error_code = ignore-without-code,redundant-expr,truthy-bool,possibly-undefined
1319
warn_unreachable = True

‎Tools/build/update_file.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,27 @@
66
actually change the in-tree generated code.
77
"""
88

9+
from __future__importannotations
10+
911
importcontextlib
1012
importos
1113
importos.path
1214
importsys
1315

16+
TYPE_CHECKING=False
17+
ifTYPE_CHECKING:
18+
importtyping
19+
fromcollections.abcimportIterator
20+
fromioimportTextIOWrapper
21+
22+
_Outcome:typing.TypeAlias=typing.Literal['created','updated','same']
23+
1424

1525
@contextlib.contextmanager
16-
defupdating_file_with_tmpfile(filename,tmpfile=None):
26+
defupdating_file_with_tmpfile(
27+
filename:str,
28+
tmpfile:str|None=None,
29+
)->Iterator[tuple[TextIOWrapper,TextIOWrapper]]:
1730
"""A context manager for updating a file via a temp file.
1831
1932
The context manager provides two open files: the source file open
@@ -46,13 +59,18 @@ def updating_file_with_tmpfile(filename, tmpfile=None):
4659
update_file_with_tmpfile(filename,tmpfile)
4760

4861

49-
defupdate_file_with_tmpfile(filename,tmpfile,*,create=False):
62+
defupdate_file_with_tmpfile(
63+
filename:str,
64+
tmpfile:str,
65+
*,
66+
create:bool=False,
67+
)->_Outcome:
5068
try:
5169
targetfile=open(filename,'rb')
5270
exceptFileNotFoundError:
5371
ifnotcreate:
5472
raise# re-raise
55-
outcome='created'
73+
outcome:_Outcome='created'
5674
os.replace(tmpfile,filename)
5775
else:
5876
withtargetfile:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp