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

Commit0b88012

Browse files
committed
Use onexc callback where supported
The shutil.rmtree callback defined as a local function ingit.util.rmtree was already capable of being used as both the oldonerror parameter and the new onexc parameter--introduced in Python3.12, which also deprecates onerror--because they differ only inthe meaning of their third parameter (excinfo), which the callbackdefined in git.util.rmtree does not use.This modifies git.util.rmtree to pass it as onexc on 3.12 andlater, while still passing it as onerror on 3.11 and earlier.Because the default value of ignore_errors is False, this makes thevarying logic clearer by omitting that argument and using a keywordargument both when passing onexc (which is keyword-only) and whenpassing onerror (which is not keyword-only but can only be passedpositionally if ignore_errors is passed explicitly).
1 parentccbb273 commit0b88012

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

‎git/util.py

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,24 @@
55
# the BSD License: https://opensource.org/license/bsd-3-clause/
66

77
fromabcimportabstractmethod
8-
importos.pathasosp
9-
from .compatimportis_win
108
importcontextlib
119
fromfunctoolsimportwraps
1210
importgetpass
1311
importlogging
1412
importos
13+
importos.pathasosp
14+
importpathlib
1515
importplatform
16-
importsubprocess
1716
importre
1817
importshutil
1918
importstat
20-
fromsysimportmaxsize
19+
importsubprocess
20+
importsys
2121
importtime
2222
fromurllib.parseimporturlsplit,urlunsplit
2323
importwarnings
2424

25-
#fromgit.objects.util importTraversable
25+
from.compatimportis_win
2626

2727
# typing ---------------------------------------------------------
2828

@@ -42,22 +42,17 @@
4242
Tuple,
4343
TypeVar,
4444
Union,
45-
cast,
4645
TYPE_CHECKING,
46+
cast,
4747
overload,
4848
)
4949

50-
importpathlib
51-
5250
ifTYPE_CHECKING:
5351
fromgit.remoteimportRemote
5452
fromgit.repo.baseimportRepo
5553
fromgit.configimportGitConfigParser,SectionConstraint
5654
fromgitimportGit
5755

58-
# from git.objects.base import IndexObject
59-
60-
6156
from .typesimport (
6257
Literal,
6358
SupportsIndex,
@@ -75,7 +70,6 @@
7570

7671
# ---------------------------------------------------------------------
7772

78-
7973
fromgitdb.utilimport (# NOQA @IgnorePep8
8074
make_sha,
8175
LockedFD,# @UnusedImport
@@ -88,7 +82,6 @@
8882
hex_to_bin,# @UnusedImport
8983
)
9084

91-
9285
# NOTE: Some of the unused imports might be used/imported by others.
9386
# Handle once test-cases are back up and running.
9487
# Most of these are unused here, but are for use by git-python modules so these
@@ -182,7 +175,7 @@ def rmtree(path: PathLike) -> None:
182175
:note: we use shutil rmtree but adjust its behaviour to see whether files that
183176
couldn't be deleted are read-only. Windows will not remove them in that case"""
184177

185-
defonerror(function:Callable,path:PathLike,_excinfo:Any)->None:
178+
defhandler(function:Callable,path:PathLike,_excinfo:Any)->None:
186179
# Is the error an access error ?
187180
os.chmod(path,stat.S_IWUSR)
188181

@@ -195,7 +188,10 @@ def onerror(function: Callable, path: PathLike, _excinfo: Any) -> None:
195188
raiseSkipTest(f"FIXME: fails with: PermissionError\n{ex}")fromex
196189
raise
197190

198-
shutil.rmtree(path,False,onerror)
191+
ifsys.version_info>= (3,12):
192+
shutil.rmtree(path,onexc=handler)
193+
else:
194+
shutil.rmtree(path,onerror=handler)
199195

200196

201197
defrmfile(path:PathLike)->None:
@@ -995,7 +991,7 @@ def __init__(
995991
self,
996992
file_path:PathLike,
997993
check_interval_s:float=0.3,
998-
max_block_time_s:int=maxsize,
994+
max_block_time_s:int=sys.maxsize,
999995
)->None:
1000996
"""Configure the instance
1001997

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp