Skip to content

Commit 06f462f

Browse files
authored
Merge branch 'main' into bugfix/pythongh-127085
2 parents c7872cd + 38264a0 commit 06f462f

9 files changed

Lines changed: 64 additions & 37 deletions

File tree

‎Doc/library/asyncio-sync.rst‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,16 +259,16 @@ Condition
259259

260260
Note that a task *may* return from this call spuriously,
261261
which is why the caller should always re-check the state
262-
and be prepared to :meth:`wait` again. For this reason, you may
263-
prefer to use :meth:`wait_for` instead.
262+
and be prepared to :meth:`~Condition.wait` again. For this reason, you may
263+
prefer to use :meth:`~Condition.wait_for` instead.
264264

265265
.. coroutinemethod:: wait_for(predicate)
266266

267267
Wait until a predicate becomes *true*.
268268

269269
The predicate must be a callable which result will be
270270
interpreted as a boolean value. The method will repeatedly
271-
:meth:`wait` until the predicate evaluates to *true*. The final value is the
271+
:meth:`~Condition.wait` until the predicate evaluates to *true*. The final value is the
272272
return value.
273273

274274

@@ -434,7 +434,7 @@ Barrier
434434
.. coroutinemethod:: abort()
435435

436436
Put the barrier into a broken state. This causes any active or future
437-
calls to :meth:`wait` to fail with the :class:`BrokenBarrierError`.
437+
calls to :meth:`~Barrier.wait` to fail with the :class:`BrokenBarrierError`.
438438
Use this for example if one of the tasks needs to abort, to avoid infinite
439439
waiting tasks.
440440

‎Lib/pathlib/_abc.py‎

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,6 @@ def stat(self, *, follow_symlinks=True):
438438
"""
439439
raise UnsupportedOperation(self._unsupported_msg('stat()'))
440440

441-
def lstat(self):
442-
"""
443-
Like stat(), except if the path points to a symlink, the symlink's
444-
status information is returned, rather than its target's.
445-
"""
446-
return self.stat(follow_symlinks=False)
447-
448-
449441
# Convenience functions for querying the stat results
450442

451443
def exists(self, *, follow_symlinks=True):
@@ -505,7 +497,7 @@ def is_symlink(self):
505497
Whether this path is a symbolic link.
506498
"""
507499
try:
508-
return S_ISLNK(self.lstat().st_mode)
500+
return S_ISLNK(self.stat(follow_symlinks=False).st_mode)
509501
except (OSError, ValueError):
510502
return False
511503

@@ -789,7 +781,7 @@ def raise_error(*args):
789781
def lstat(path_str):
790782
path = self.with_segments(path_str)
791783
path._resolving = True
792-
return path.lstat()
784+
return path.stat(follow_symlinks=False)
793785

794786
def readlink(path_str):
795787
path = self.with_segments(path_str)

‎Lib/pathlib/_local.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,13 @@ def stat(self, *, follow_symlinks=True):
542542
"""
543543
return os.stat(self, follow_symlinks=follow_symlinks)
544544

545+
def lstat(self):
546+
"""
547+
Like stat(), except if the path points to a symlink, the symlink's
548+
status information is returned, rather than its target's.
549+
"""
550+
return os.lstat(self)
551+
545552
def exists(self, *, follow_symlinks=True):
546553
"""
547554
Whether this path exists.

‎Lib/test/test_free_threading/test_type.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ def work():
124124
for thread in threads:
125125
thread.join()
126126

127+
def test_object_class_change(self):
128+
class Base:
129+
def __init__(self):
130+
self.attr = 123
131+
class ClassA(Base):
132+
pass
133+
class ClassB(Base):
134+
pass
135+
136+
obj = ClassA()
137+
# keep reference to __dict__
138+
d = obj.__dict__
139+
obj.__class__ = ClassB
140+
141+
127142
def run_one(self, writer_func, reader_func):
128143
writer = Thread(target=writer_func)
129144
readers = []

‎Lib/test/test_import/__init__.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,19 @@ def test_script_shadowing_stdlib_sys_path_modification(self):
11331133
stdout, stderr = popen.communicate()
11341134
self.assertRegex(stdout, expected_error)
11351135

1136+
def test_create_dynamic_null(self):
1137+
with self.assertRaisesRegex(ValueError, 'embedded null character'):
1138+
class Spec:
1139+
name = "a\x00b"
1140+
origin = "abc"
1141+
_imp.create_dynamic(Spec())
1142+
1143+
with self.assertRaisesRegex(ValueError, 'embedded null character'):
1144+
class Spec2:
1145+
name = "abc"
1146+
origin = "a\x00b"
1147+
_imp.create_dynamic(Spec2())
1148+
11361149

11371150
@skip_if_dont_write_bytecode
11381151
class FilePermissionTests(unittest.TestCase):

‎Lib/test/test_pathlib/test_pathlib.py‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,9 @@ def tempdir(self):
546546
self.addCleanup(os_helper.rmtree, d)
547547
return d
548548

549-
def test_matches_pathbase_api(self):
550-
our_names = {name for name in dir(self.cls) if name[0] != '_'}
551-
our_names.remove('is_reserved') # only present in PurePath
549+
def test_matches_pathbase_docstrings(self):
552550
path_names = {name for name in dir(pathlib._abc.PathBase) if name[0] != '_'}
553-
self.assertEqual(our_names, path_names)
554-
for attr_name in our_names:
551+
for attr_name in path_names:
555552
if attr_name == 'parser':
556553
# On Windows, Path.parser is ntpath, but PathBase.parser is
557554
# posixpath, and so their docstrings differ.
@@ -1357,6 +1354,17 @@ def test_symlink_to_unsupported(self):
13571354
with self.assertRaises(pathlib.UnsupportedOperation):
13581355
q.symlink_to(p)
13591356

1357+
@needs_symlinks
1358+
def test_lstat(self):
1359+
p = self.cls(self.base)/ 'linkA'
1360+
st = p.stat()
1361+
self.assertNotEqual(st, p.lstat())
1362+
1363+
def test_lstat_nosymlink(self):
1364+
p = self.cls(self.base) / 'fileA'
1365+
st = p.stat()
1366+
self.assertEqual(st, p.lstat())
1367+
13601368
def test_is_junction(self):
13611369
P = self.cls(self.base)
13621370

‎Lib/test/test_pathlib/test_pathlib_abc.py‎

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,7 +1351,6 @@ def test_unsupported_operation(self):
13511351
p = self.cls('')
13521352
e = UnsupportedOperation
13531353
self.assertRaises(e, p.stat)
1354-
self.assertRaises(e, p.lstat)
13551354
self.assertRaises(e, p.exists)
13561355
self.assertRaises(e, p.samefile, 'foo')
13571356
self.assertRaises(e, p.is_dir)
@@ -2671,17 +2670,6 @@ def test_stat_no_follow_symlinks_nosymlink(self):
26712670
st = p.stat()
26722671
self.assertEqual(st, p.stat(follow_symlinks=False))
26732672

2674-
@needs_symlinks
2675-
def test_lstat(self):
2676-
p = self.cls(self.base)/ 'linkA'
2677-
st = p.stat()
2678-
self.assertNotEqual(st, p.lstat())
2679-
2680-
def test_lstat_nosymlink(self):
2681-
p = self.cls(self.base) / 'fileA'
2682-
st = p.stat()
2683-
self.assertEqual(st, p.lstat())
2684-
26852673
def test_is_dir(self):
26862674
P = self.cls(self.base)
26872675
self.assertTrue((P / 'dirA').is_dir())
@@ -2868,11 +2856,13 @@ def test_delete_dir(self):
28682856
base = self.cls(self.base)
28692857
base.joinpath('dirA')._delete()
28702858
self.assertRaises(FileNotFoundError, base.joinpath('dirA').stat)
2871-
self.assertRaises(FileNotFoundError, base.joinpath('dirA', 'linkC').lstat)
2859+
self.assertRaises(FileNotFoundError, base.joinpath('dirA', 'linkC').stat,
2860+
follow_symlinks=False)
28722861
base.joinpath('dirB')._delete()
28732862
self.assertRaises(FileNotFoundError, base.joinpath('dirB').stat)
28742863
self.assertRaises(FileNotFoundError, base.joinpath('dirB', 'fileB').stat)
2875-
self.assertRaises(FileNotFoundError, base.joinpath('dirB', 'linkD').lstat)
2864+
self.assertRaises(FileNotFoundError, base.joinpath('dirB', 'linkD').stat,
2865+
follow_symlinks=False)
28762866
base.joinpath('dirC')._delete()
28772867
self.assertRaises(FileNotFoundError, base.joinpath('dirC').stat)
28782868
self.assertRaises(FileNotFoundError, base.joinpath('dirC', 'dirD').stat)

‎Objects/dictobject.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7300,7 +7300,7 @@ _PyDict_DetachFromObject(PyDictObject *mp, PyObject *obj)
73007300

73017301
// We could be called with an unlocked dict when the caller knows the
73027302
// values are already detached, so we assert after inline values check.
7303-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(mp);
7303+
ASSERT_WORLD_STOPPED_OR_OBJ_LOCKED(mp);
73047304
assert(mp->ma_values->embedded == 1);
73057305
assert(mp->ma_values->valid == 1);
73067306
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_INLINE_VALUES);

‎Python/import.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,12 +1157,14 @@ del_extensions_cache_value(struct extensions_cache_value *value)
11571157
static void *
11581158
hashtable_key_from_2_strings(PyObject *str1, PyObject *str2, const char sep)
11591159
{
1160-
Py_ssize_t str1_len, str2_len;
1161-
const char *str1_data = PyUnicode_AsUTF8AndSize(str1, &str1_len);
1162-
const char *str2_data = PyUnicode_AsUTF8AndSize(str2, &str2_len);
1160+
const char *str1_data = _PyUnicode_AsUTF8NoNUL(str1);
1161+
const char *str2_data = _PyUnicode_AsUTF8NoNUL(str2);
11631162
if (str1_data == NULL || str2_data == NULL) {
11641163
return NULL;
11651164
}
1165+
Py_ssize_t str1_len = strlen(str1_data);
1166+
Py_ssize_t str2_len = strlen(str2_data);
1167+
11661168
/* Make sure sep and the NULL byte won't cause an overflow. */
11671169
assert(SIZE_MAX - str1_len - str2_len > 2);
11681170
size_t size = str1_len + 1 + str2_len + 1;

0 commit comments

Comments
 (0)