Skip to content

Commit 27fce1f

Browse files
author
Release Manager
committed
gh-38646: add typing annotation in temporary_file
add some typing annotation in the modified file also remove one unused import and some traces of python 2 ### 📝 Checklist - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. URL: #38646 Reported by: Frédéric Chapoton Reviewer(s): Vincent Macri
2 parents c82c509 + 7fc7e9b commit 27fce1f

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

build/pkgs/configure/checksums.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
tarball=configure-VERSION.tar.gz
2-
sha1=0f6355fc136bb6619585863b9e4bc954cc6e0e3d
3-
sha256=5b618581d51997afa78b5e6647584f7ef4e6d5844823dd44e607f2accd7abba5
2+
sha1=b08e077178bfe0d44d6028e67233ab008dd8dd05
3+
sha256=49ef0dab4287764522f7290d51ebbfe38492b2695201d87dd8452020a3b4d9d6
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
b9cb7bc2559cde857d84d77f0b37a3616ce1eb6c
1+
448f7e212e38ad2bd0ed6be7ae8cad1cb3615913

src/sage/misc/replace_dot_all.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ def walkdir_replace_dot_all(dir, file_regex=r'.*[.](py|pyx|pxi)$', package_regex
456456
finally:
457457
# Print report also when interrupted
458458
if verbosity:
459-
log_messages = sorted(log_messages.rstrip().split('\n'))
460-
for i, message in enumerate(log_messages, start=1):
459+
log_messages_split = sorted(log_messages.rstrip().split('\n'))
460+
for i, message in enumerate(log_messages_split, start=1):
461461
# add index to each line
462462
print(f'{i}. {message.rstrip()}')
463463
report = 'REPORT:\n'

src/sage/misc/temporary_file.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@
2323
# https://www.gnu.org/licenses/
2424
# ****************************************************************************
2525

26-
import io
26+
import atexit
2727
import os
2828
import tempfile
29-
30-
import atexit
29+
from typing import IO
3130

3231
# Until tmp_dir() and tmp_filename() are removed, we use this directory
3332
# as the parent for all temporary files & directories created by them.
@@ -41,7 +40,7 @@
4140
# temporary directory
4241
#################################################################
4342

44-
def tmp_dir(name='dir_', ext=''):
43+
def tmp_dir(name='dir_', ext='') -> str:
4544
r"""
4645
Create and return a temporary directory in
4746
``$HOME/.sage/temp/hostname/pid/``
@@ -84,7 +83,7 @@ def tmp_dir(name='dir_', ext=''):
8483
# temporary filename
8584
#################################################################
8685

87-
def tmp_filename(name='tmp_', ext=''):
86+
def tmp_filename(name='tmp_', ext='') -> str:
8887
r"""
8988
Create and return a temporary file in
9089
``$HOME/.sage/temp/hostname/pid/``
@@ -163,8 +162,8 @@ class atomic_write:
163162
mode bits of the file were changed manually). (Not to be confused with
164163
the file opening mode.)
165164
166-
- ``binary`` -- boolean (default: ``True`` on Python 2, ``False`` on Python
167-
3); the underlying file is opened in binary mode. If ``False`` then it is
165+
- ``binary`` -- boolean (default: ``False``);
166+
the underlying file is opened in binary mode. If ``False`` then it is
168167
opened in text mode and an encoding with which to write the file may be
169168
supplied.
170169
@@ -299,7 +298,7 @@ class atomic_write:
299298
False
300299
"""
301300
def __init__(self, target_filename, append=False, mode=0o666,
302-
binary=None, **kwargs):
301+
binary=False, **kwargs) -> None:
303302
"""
304303
TESTS::
305304
@@ -320,13 +319,11 @@ def __init__(self, target_filename, append=False, mode=0o666,
320319
os.umask(umask)
321320
self.mode = mode & (~umask)
322321

323-
# 'binary' mode is the default on Python 2, whereas 'text' mode is the
324-
# default on Python 3--this reflects consistent handling of the default
325-
# str type on the two platforms
326-
self.binary = False if binary is None else binary
322+
# 'text' mode is the default on Python 3
323+
self.binary = binary
327324
self.kwargs = kwargs
328325

329-
def __enter__(self):
326+
def __enter__(self) -> IO:
330327
"""
331328
Create and return a temporary file in ``self.tmpdir`` (normally
332329
the same directory as the target file).
@@ -372,7 +369,7 @@ def __enter__(self):
372369

373370
return self.tempfile
374371

375-
def __exit__(self, exc_type, exc_val, exc_tb):
372+
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
376373
"""
377374
If the ``with`` block was successful, move the temporary file
378375
to the target file. Otherwise, delete the temporary file.
@@ -457,7 +454,7 @@ class atomic_dir:
457454
....: h.read()
458455
'Second'
459456
"""
460-
def __init__(self, target_directory):
457+
def __init__(self, target_directory) -> None:
461458
r"""
462459
TESTS::
463460
@@ -492,7 +489,7 @@ def __enter__(self):
492489
self.tempname = os.path.abspath(tdir.name)
493490
return tdir
494491

495-
def __exit__(self, exc_type, exc_val, exc_tb):
492+
def __exit__(self, exc_type, exc_val, exc_tb) -> None:
496493
"""
497494
If the ``with`` block was successful, move the temporary directory
498495
to the target directory. Otherwise, delete the temporary directory.
@@ -518,7 +515,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
518515
try:
519516
os.rename(self.tempname, self.target)
520517
except OSError:
521-
# Race: Another thread or process must have created the directory
518+
# Race: Another thread or process must have created
519+
# the directory
522520
pass
523521
else:
524522
# Failure: delete temporary file
@@ -528,7 +526,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
528526
_spyx_tmp = None
529527

530528

531-
def spyx_tmp():
529+
def spyx_tmp() -> str:
532530
r"""
533531
The temporary directory used to store pyx files.
534532

0 commit comments

Comments
 (0)