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

Commitab84a68

Browse files
committed
Merge remote-tracking branch 'upstream/main' into DisplayException
2 parents2c4f399 +0f17576 commitab84a68

File tree

22 files changed

+552
-175
lines changed

22 files changed

+552
-175
lines changed

‎Doc/library/os.rst‎

Lines changed: 65 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2858,6 +2858,12 @@ features:
28582858
Added support for the:class:`~os.PathLike` interface. Added support
28592859
for:class:`bytes` paths on Windows.
28602860

2861+
..versionchanged::3.12
2862+
The ``st_ctime`` attribute of a stat result is deprecated on Windows.
2863+
The file creation time is properly available as ``st_birthtime``, and
2864+
in the future ``st_ctime`` may be changed to return zero or the
2865+
metadata change time, if available.
2866+
28612867

28622868
..function::stat(path, *, dir_fd=None, follow_symlinks=True)
28632869

@@ -2973,10 +2979,12 @@ features:
29732979

29742980
..attribute::st_ctime
29752981

2976-
Platform dependent:
2982+
Time of most recent metadata change expressed in seconds.
29772983

2978-
* the time of most recent metadata change on Unix,
2979-
* the time of creation on Windows, expressed in seconds.
2984+
..versionchanged::3.12
2985+
``st_ctime`` is deprecated on Windows. Use ``st_birthtime`` for
2986+
the file creation time. In the future, ``st_ctime`` will contain
2987+
the time of the most recent metadata change, as for other platforms.
29802988

29812989
..attribute::st_atime_ns
29822990

@@ -2989,29 +2997,48 @@ features:
29892997

29902998
..attribute::st_ctime_ns
29912999

2992-
Platform dependent:
3000+
Time of most recent metadata change expressed in nanoseconds as an
3001+
integer.
3002+
3003+
..versionchanged::3.12
3004+
``st_ctime_ns`` is deprecated on Windows. Use ``st_birthtime_ns``
3005+
for the file creation time. In the future, ``st_ctime`` will contain
3006+
the time of the most recent metadata change, as for other platforms.
3007+
3008+
..attribute::st_birthtime
3009+
3010+
Time of file creation expressed in seconds. This attribute is not
3011+
always available, and may raise:exc:`AttributeError`.
3012+
3013+
..versionchanged::3.12
3014+
``st_birthtime`` is now available on Windows.
3015+
3016+
..attribute::st_birthtime_ns
29933017

2994-
* the time of most recent metadata change on Unix,
2995-
* the time of creation on Windows, expressed in nanoseconds as an
2996-
integer.
3018+
Time of file creation expressed in nanoseconds as an integer.
3019+
This attribute is not always available, and may raise
3020+
:exc:`AttributeError`.
3021+
3022+
..versionadded::3.12
29973023

29983024
..note::
29993025

30003026
The exact meaning and resolution of the:attr:`st_atime`,
3001-
:attr:`st_mtime`,and:attr:`st_ctime`attributes depend on the operating
3002-
system and the file system. For example, on Windows systems using the FAT
3003-
orFAT32 file systems,:attr:`st_mtime` has 2-second resolution, and
3004-
:attr:`st_atime` has only 1-day resolution. See your operating system
3005-
documentation for details.
3027+
:attr:`st_mtime`,:attr:`st_ctime`and:attr:`st_birthtime` attributes
3028+
depend on the operatingsystem and the file system. For example, on
3029+
Windows systems using theFAT32 file systems,:attr:`st_mtime` has
3030+
2-second resolution, and:attr:`st_atime` has only 1-day resolution.
3031+
See your operating systemdocumentation for details.
30063032

30073033
Similarly, although:attr:`st_atime_ns`,:attr:`st_mtime_ns`,
3008-
and:attr:`st_ctime_ns` are always expressed in nanoseconds, many
3009-
systems do not provide nanosecond precision. On systems that do
3010-
provide nanosecond precision, the floating-point object used to
3011-
store:attr:`st_atime`,:attr:`st_mtime`, and:attr:`st_ctime`
3012-
cannot preserve all of it, and as such will be slightly inexact.
3013-
If you need the exact timestamps you should always use
3014-
:attr:`st_atime_ns`,:attr:`st_mtime_ns`, and:attr:`st_ctime_ns`.
3034+
:attr:`st_ctime_ns` and:attr:`st_birthtime_ns` are always expressed in
3035+
nanoseconds, many systems do not provide nanosecond precision. On
3036+
systems that do provide nanosecond precision, the floating-point object
3037+
used to store:attr:`st_atime`,:attr:`st_mtime`,:attr:`st_ctime` and
3038+
:attr:`st_birthtime` cannot preserve all of it, and as such will be
3039+
slightly inexact. If you need the exact timestamps you should always use
3040+
:attr:`st_atime_ns`,:attr:`st_mtime_ns`,:attr:`st_ctime_ns` and
3041+
:attr:`st_birthtime_ns`.
30153042

30163043
On some Unix systems (such as Linux), the following attributes may also be
30173044
available:
@@ -3041,10 +3068,6 @@ features:
30413068

30423069
File generation number.
30433070

3044-
..attribute::st_birthtime
3045-
3046-
Time of file creation.
3047-
30483071
On Solaris and derivatives, the following attributes may also be
30493072
available:
30503073

@@ -3117,6 +3140,25 @@ features:
31173140
files as:const:`S_IFCHR`,:const:`S_IFIFO` or:const:`S_IFBLK`
31183141
as appropriate.
31193142

3143+
..versionchanged::3.12
3144+
On Windows,:attr:`st_ctime` is deprecated. Eventually, it will
3145+
contain the last metadata change time, for consistency with other
3146+
platforms, but for now still contains creation time.
3147+
Use:attr:`st_birthtime` for the creation time.
3148+
3149+
..versionchanged::3.12
3150+
On Windows,:attr:`st_ino` may now be up to 128 bits, depending
3151+
on the file system. Previously it would not be above 64 bits, and
3152+
larger file identifiers would be arbitrarily packed.
3153+
3154+
..versionchanged::3.12
3155+
On Windows,:attr:`st_rdev` no longer returns a value. Previously
3156+
it would contain the same as:attr:`st_dev`, which was incorrect.
3157+
3158+
..versionadded::3.12
3159+
Added the:attr:`st_birthtime` member on Windows.
3160+
3161+
31203162
..function::statvfs(path)
31213163

31223164
Perform a:c:func:`statvfs` system call on the given path. The return value is

‎Doc/library/random.rst‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ from the combinatoric iterators in the :mod:`itertools` module:
610610
return tuple(pool[i] for i in indices)
611611

612612
def random_combination_with_replacement(iterable, r):
613-
"Random selection from itertools.combinations_with_replacement(iterable, r)"
613+
"Choose r elements with replacement. Order the result to match the iterable."
614+
# Result will be in set(itertools.combinations_with_replacement(iterable, r)).
614615
pool = tuple(iterable)
615616
n = len(pool)
616617
indices = sorted(random.choices(range(n), k=r))

‎Doc/whatsnew/3.12.rst‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ asyncio
237237
* Add C implementation of:func:`asyncio.current_task` for 4x-6x speedup.
238238
(Contributed by Itamar Ostricher and Pranav Thulasiram Bhat in:gh:`100344`.)
239239

240+
*:func:`asyncio.iscoroutine` now returns ``False`` for generators as
241+
:mod:`asyncio` does not support legacy generator-based coroutines.
242+
(Contributed by Kumar Aditya in:gh:`102748`.)
243+
240244
inspect
241245
-------
242246

@@ -302,6 +306,16 @@ os
302306
functions on Windows for enumerating drives, volumes and mount points.
303307
(Contributed by Steve Dower in:gh:`102519`.)
304308

309+
*:func:`os.stat` and:func:`os.lstat` are now more accurate on Windows.
310+
The ``st_birthtime`` field will now be filled with the creation time
311+
of the file, and ``st_ctime`` is deprecated but still contains the
312+
creation time (but in the future will return the last metadata change,
313+
for consistency with other platforms). ``st_dev`` may be up to 64 bits
314+
and ``st_ino`` up to 128 bits depending on your file system, and
315+
``st_rdev`` is always set to zero rather than incorrect values.
316+
Both functions may be significantly faster on newer releases of
317+
Windows. (Contributed by Steve Dower in:gh:`99726`.)
318+
305319
os.path
306320
-------
307321

@@ -465,6 +479,12 @@ Deprecated
465479
warning at compile time. This field will be removed in Python 3.14.
466480
(Contributed by Ramvikrams and Kumar Aditya in:gh:`101193`. PEP by Ken Jin.)
467481

482+
* The ``st_ctime`` fields return by:func:`os.stat` and:func:`os.lstat` on
483+
Windows are deprecated. In a future release, they will contain the last
484+
metadata change time, consistent with other platforms. For now, they still
485+
contain the creation time, which is also available in the new ``st_birthtime``
486+
field. (Contributed by Steve Dower in:gh:`99726`.)
487+
468488
Pending Removal in Python 3.13
469489
------------------------------
470490

‎Include/internal/pycore_fileutils.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ PyAPI_FUNC(PyObject *) _Py_device_encoding(int);
6666

6767
#ifdefMS_WINDOWS
6868
struct_Py_stat_struct {
69-
unsigned longst_dev;
69+
uint64_tst_dev;
7070
uint64_tst_ino;
7171
unsigned shortst_mode;
7272
intst_nlink;
@@ -80,8 +80,11 @@ struct _Py_stat_struct {
8080
intst_mtime_nsec;
8181
time_tst_ctime;
8282
intst_ctime_nsec;
83+
time_tst_birthtime;
84+
intst_birthtime_nsec;
8385
unsigned longst_file_attributes;
8486
unsigned longst_reparse_tag;
87+
uint64_tst_ino_high;
8588
};
8689
#else
8790
# define_Py_stat_struct stat
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#ifndefPy_INTERNAL_FILEUTILS_WINDOWS_H
2+
#definePy_INTERNAL_FILEUTILS_WINDOWS_H
3+
#ifdef__cplusplus
4+
extern"C" {
5+
#endif
6+
7+
#ifndefPy_BUILD_CORE
8+
# error "Py_BUILD_CORE must be defined to include this header"
9+
#endif
10+
11+
#ifdefMS_WINDOWS
12+
13+
#if !defined(NTDDI_WIN10_NI)|| !(NTDDI_VERSION >=NTDDI_WIN10_NI)
14+
typedefstruct_FILE_STAT_BASIC_INFORMATION {
15+
LARGE_INTEGERFileId;
16+
LARGE_INTEGERCreationTime;
17+
LARGE_INTEGERLastAccessTime;
18+
LARGE_INTEGERLastWriteTime;
19+
LARGE_INTEGERChangeTime;
20+
LARGE_INTEGERAllocationSize;
21+
LARGE_INTEGEREndOfFile;
22+
ULONGFileAttributes;
23+
ULONGReparseTag;
24+
ULONGNumberOfLinks;
25+
ULONGDeviceType;
26+
ULONGDeviceCharacteristics;
27+
ULONGReserved;
28+
FILE_ID_128FileId128;
29+
LARGE_INTEGERVolumeSerialNumber;
30+
}FILE_STAT_BASIC_INFORMATION;
31+
32+
typedefenum_FILE_INFO_BY_NAME_CLASS {
33+
FileStatByNameInfo,
34+
FileStatLxByNameInfo,
35+
FileCaseSensitiveByNameInfo,
36+
FileStatBasicByNameInfo,
37+
MaximumFileInfoByNameClass
38+
}FILE_INFO_BY_NAME_CLASS;
39+
#endif
40+
41+
typedefBOOL (WINAPI*PGetFileInformationByName)(
42+
PCWSTRFileName,
43+
FILE_INFO_BY_NAME_CLASSFileInformationClass,
44+
PVOIDFileInfoBuffer,
45+
ULONGFileInfoBufferSize
46+
);
47+
48+
staticinlineBOOL_Py_GetFileInformationByName(
49+
PCWSTRFileName,
50+
FILE_INFO_BY_NAME_CLASSFileInformationClass,
51+
PVOIDFileInfoBuffer,
52+
ULONGFileInfoBufferSize
53+
) {
54+
staticPGetFileInformationByNameGetFileInformationByName=NULL;
55+
staticintGetFileInformationByName_init=-1;
56+
57+
if (GetFileInformationByName_init<0) {
58+
HMODULEhMod=LoadLibraryW(L"api-ms-win-core-file-l2-1-4");
59+
GetFileInformationByName_init=0;
60+
if (hMod) {
61+
GetFileInformationByName= (PGetFileInformationByName)GetProcAddress(
62+
hMod,"GetFileInformationByName");
63+
if (GetFileInformationByName) {
64+
GetFileInformationByName_init=1;
65+
}else {
66+
FreeLibrary(hMod);
67+
}
68+
}
69+
}
70+
71+
if (GetFileInformationByName_init <=0) {
72+
SetLastError(ERROR_NOT_SUPPORTED);
73+
return FALSE;
74+
}
75+
returnGetFileInformationByName(FileName,FileInformationClass,FileInfoBuffer,FileInfoBufferSize);
76+
}
77+
78+
#endif
79+
80+
#endif

‎Lib/_collections_abc.py‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,8 @@ def __getitem__(self, item):
481481
# rather than the default types.GenericAlias object. Most of the
482482
# code is copied from typing's _GenericAlias and the builtin
483483
# types.GenericAlias.
484-
485484
ifnotisinstance(item,tuple):
486485
item= (item,)
487-
# A special case in PEP 612 where if X = Callable[P, int],
488-
# then X[int, str] == X[[int, str]].
489-
if (len(self.__parameters__)==1
490-
and_is_param_expr(self.__parameters__[0])
491-
anditemandnot_is_param_expr(item[0])):
492-
item= (item,)
493486

494487
new_args=super().__getitem__(item).__args__
495488

@@ -517,9 +510,8 @@ def _type_repr(obj):
517510
518511
Copied from :mod:`typing` since collections.abc
519512
shouldn't depend on that module.
513+
(Keep this roughly in sync with the typing version.)
520514
"""
521-
ifisinstance(obj,GenericAlias):
522-
returnrepr(obj)
523515
ifisinstance(obj,type):
524516
ifobj.__module__=='builtins':
525517
returnobj.__qualname__

‎Lib/asyncio/coroutines.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ def iscoroutinefunction(func):
2525

2626
# Prioritize native coroutine check to speed-up
2727
# asyncio.iscoroutine.
28-
_COROUTINE_TYPES= (types.CoroutineType,types.GeneratorType,
29-
collections.abc.Coroutine)
28+
_COROUTINE_TYPES= (types.CoroutineType,collections.abc.Coroutine)
3029
_iscoroutine_typecache=set()
3130

3231

‎Lib/test/test_asyncio/test_pep492.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ async def foo(): pass
119119

120120
self.assertTrue(asyncio.iscoroutine(FakeCoro()))
121121

122+
deftest_iscoroutine_generator(self):
123+
deffoo():yield
124+
125+
self.assertFalse(asyncio.iscoroutine(foo()))
126+
127+
122128
deftest_iscoroutinefunction(self):
123129
asyncdeffoo():pass
124130
self.assertTrue(asyncio.iscoroutinefunction(foo))

‎Lib/test/test_os.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,15 @@ def trunc(x): return x
556556
nanosecondy=getattr(result,name+"_ns")//10000
557557
self.assertAlmostEqual(floaty,nanosecondy,delta=2)
558558

559+
# Ensure both birthtime and birthtime_ns roughly agree, if present
560+
try:
561+
floaty=int(result.st_birthtime*100000)
562+
nanosecondy=result.st_birthtime_ns//10000
563+
exceptAttributeError:
564+
pass
565+
else:
566+
self.assertAlmostEqual(floaty,nanosecondy,delta=2)
567+
559568
try:
560569
result[200]
561570
self.fail("No exception raised")
@@ -4234,7 +4243,8 @@ def assert_stat_equal(self, stat1, stat2, skip_fields):
42344243
forattrindir(stat1):
42354244
ifnotattr.startswith("st_"):
42364245
continue
4237-
ifattrin ("st_dev","st_ino","st_nlink"):
4246+
ifattrin ("st_dev","st_ino","st_nlink","st_ctime",
4247+
"st_ctime_ns"):
42384248
continue
42394249
self.assertEqual(getattr(stat1,attr),
42404250
getattr(stat2,attr),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp