Skip to content

Commit 32f0d1a

Browse files
committed
Merge branch 'main' into windows-sys-abiflags
2 parents b259c5e + 4e0a4ca commit 32f0d1a

File tree

13 files changed

+163
-99
lines changed

13 files changed

+163
-99
lines changed

Doc/c-api/type.rst

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -529,19 +529,19 @@ The following functions and structs are used to create
529529
530530
The following “offset” fields cannot be set using :c:type:`PyType_Slot`:
531531
532-
* :c:member:`~PyTypeObject.tp_weaklistoffset`
533-
(use :c:macro:`Py_TPFLAGS_MANAGED_WEAKREF` instead if possible)
534-
* :c:member:`~PyTypeObject.tp_dictoffset`
535-
(use :c:macro:`Py_TPFLAGS_MANAGED_DICT` instead if possible)
536-
* :c:member:`~PyTypeObject.tp_vectorcall_offset`
537-
(use ``"__vectorcalloffset__"`` in
538-
:ref:`PyMemberDef <pymemberdef-offsets>`)
539-
540-
If it is not possible to switch to a ``MANAGED`` flag (for example,
541-
for vectorcall or to support Python older than 3.12), specify the
542-
offset in :c:member:`Py_tp_members <PyTypeObject.tp_members>`.
543-
See :ref:`PyMemberDef documentation <pymemberdef-offsets>`
544-
for details.
532+
* :c:member:`~PyTypeObject.tp_weaklistoffset`
533+
(use :c:macro:`Py_TPFLAGS_MANAGED_WEAKREF` instead if possible)
534+
* :c:member:`~PyTypeObject.tp_dictoffset`
535+
(use :c:macro:`Py_TPFLAGS_MANAGED_DICT` instead if possible)
536+
* :c:member:`~PyTypeObject.tp_vectorcall_offset`
537+
(use ``"__vectorcalloffset__"`` in
538+
:ref:`PyMemberDef <pymemberdef-offsets>`)
539+
540+
If it is not possible to switch to a ``MANAGED`` flag (for example,
541+
for vectorcall or to support Python older than 3.12), specify the
542+
offset in :c:member:`Py_tp_members <PyTypeObject.tp_members>`.
543+
See :ref:`PyMemberDef documentation <pymemberdef-offsets>`
544+
for details.
545545
546546
The following internal fields cannot be set at all when creating a heap
547547
type:
@@ -557,20 +557,18 @@ The following functions and structs are used to create
557557
To avoid issues, use the *bases* argument of
558558
:c:func:`PyType_FromSpecWithBases` instead.
559559
560-
.. versionchanged:: 3.9
561-
562-
Slots in :c:type:`PyBufferProcs` may be set in the unlimited API.
560+
.. versionchanged:: 3.9
561+
Slots in :c:type:`PyBufferProcs` may be set in the unlimited API.
563562
564-
.. versionchanged:: 3.11
565-
:c:member:`~PyBufferProcs.bf_getbuffer` and
566-
:c:member:`~PyBufferProcs.bf_releasebuffer` are now available
567-
under the :ref:`limited API <limited-c-api>`.
563+
.. versionchanged:: 3.11
564+
:c:member:`~PyBufferProcs.bf_getbuffer` and
565+
:c:member:`~PyBufferProcs.bf_releasebuffer` are now available
566+
under the :ref:`limited API <limited-c-api>`.
568567
569-
.. versionchanged:: 3.14
570-
571-
The field :c:member:`~PyTypeObject.tp_vectorcall` can now set
572-
using ``Py_tp_vectorcall``. See the field's documentation
573-
for details.
568+
.. versionchanged:: 3.14
569+
The field :c:member:`~PyTypeObject.tp_vectorcall` can now set
570+
using ``Py_tp_vectorcall``. See the field's documentation
571+
for details.
574572
575573
.. c:member:: void *pfunc
576574

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

InternalDocs/code_objects.md

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Code objects
32

43
A `CodeObject` is a builtin Python type that represents a compiled executable,
@@ -43,7 +42,7 @@ so a compact format is very important.
4342
Note that traceback objects don't store all this information -- they store the start line
4443
number, for backward compatibility, and the "last instruction" value.
4544
The rest can be computed from the last instruction (`tb_lasti`) with the help of the
46-
locations table. For Python code, there is a convenience method
45+
locations table. For Python code, there is a convenience method
4746
(`codeobject.co_positions`)[https://docs.python.org/dev/reference/datamodel.html#codeobject.co_positions]
4847
which returns an iterator of `({line}, {endline}, {column}, {endcolumn})` tuples,
4948
one per instruction.
@@ -75,9 +74,11 @@ returned by the `co_positions()` iterator.
7574
> See [`Objects/lnotab_notes.txt`](../Objects/lnotab_notes.txt) for more details.
7675
7776
`co_linetable` consists of a sequence of location entries.
78-
Each entry starts with a byte with the most significant bit set, followed by zero or more bytes with the most significant bit unset.
77+
Each entry starts with a byte with the most significant bit set, followed by
78+
zero or more bytes with the most significant bit unset.
7979

8080
Each entry contains the following information:
81+
8182
* The number of code units covered by this entry (length)
8283
* The start line
8384
* The end line
@@ -86,54 +87,88 @@ Each entry contains the following information:
8687

8788
The first byte has the following format:
8889

89-
Bit 7 | Bits 3-6 | Bits 0-2
90-
---- | ---- | ----
91-
1 | Code | Length (in code units) - 1
90+
| Bit 7 | Bits 3-6 | Bits 0-2 |
91+
|-------|----------|----------------------------|
92+
| 1 | Code | Length (in code units) - 1 |
9293

9394
The codes are enumerated in the `_PyCodeLocationInfoKind` enum.
9495

95-
## Variable-length integer encodings
96+
### Variable-length integer encodings
9697

97-
Integers are often encoded using a variable-length integer encoding
98+
Integers are often encoded using a variable length integer encoding
9899

99-
### Unsigned integers (`varint`)
100+
#### Unsigned integers (`varint`)
100101

101102
Unsigned integers are encoded in 6-bit chunks, least significant first.
102103
Each chunk but the last has bit 6 set.
103104
For example:
104105

105106
* 63 is encoded as `0x3f`
106-
* 200 is encoded as `0x48`, `0x03`
107+
* 200 is encoded as `0x48`, `0x03` since ``200 = (0x03 << 6) | 0x48``.
108+
109+
The following helper can be used to convert an integer into a `varint`:
110+
111+
```py
112+
def encode_varint(s):
113+
ret = []
114+
while s >= 64:
115+
ret.append(((s & 0x3F) | 0x40) & 0x3F)
116+
s >>= 6
117+
ret.append(s & 0x3F)
118+
return bytes(ret)
119+
```
120+
121+
To convert a `varint` into an unsigned integer:
122+
123+
```py
124+
def decode_varint(chunks):
125+
ret = 0
126+
for chunk in reversed(chunks):
127+
ret = (ret << 6) | chunk
128+
return ret
129+
```
107130

108-
### Signed integers (`svarint`)
131+
#### Signed integers (`svarint`)
109132

110133
Signed integers are encoded by converting them to unsigned integers, using the following function:
111-
```Python
112-
def convert(s):
134+
135+
```py
136+
def svarint_to_varint(s):
113137
if s < 0:
114-
return ((-s)<<1) | 1
138+
return ((-s) << 1) | 1
115139
else:
116-
return (s<<1)
140+
return s << 1
141+
```
142+
143+
To convert a `varint` into a signed integer:
144+
145+
```py
146+
def varint_to_svarint(uval):
147+
return -(uval >> 1) if uval & 1 else (uval >> 1)
117148
```
118149

119-
*Location entries*
150+
### Location entries
120151

121152
The meaning of the codes and the following bytes are as follows:
122153

123-
Code | Meaning | Start line | End line | Start column | End column
124-
---- | ---- | ---- | ---- | ---- | ----
125-
0-9 | Short form | Δ 0 | Δ 0 | See below | See below
126-
10-12 | One line form | Δ (code - 10) | Δ 0 | unsigned byte | unsigned byte
127-
13 | No column info | Δ svarint | Δ 0 | None | None
128-
14 | Long form | Δ svarint | Δ varint | varint | varint
129-
15 | No location | None | None | None | None
154+
| Code | Meaning | Start line | End line | Start column | End column |
155+
|-------|----------------|---------------|----------|---------------|---------------|
156+
| 0-9 | Short form | Δ 0 | Δ 0 | See below | See below |
157+
| 10-12 | One line form | Δ (code - 10) | Δ 0 | unsigned byte | unsigned byte |
158+
| 13 | No column info | Δ svarint | Δ 0 | None | None |
159+
| 14 | Long form | Δ svarint | Δ varint | varint | varint |
160+
| 15 | No location | None | None | None | None |
130161

131162
The Δ means the value is encoded as a delta from another value:
163+
132164
* Start line: Delta from the previous start line, or `co_firstlineno` for the first entry.
133-
* End line: Delta from the start line
165+
* End line: Delta from the start line.
166+
167+
### The short forms
134168

135-
*The short forms*
169+
Codes 0-9 are the short forms. The short form consists of two bytes,
170+
the second byte holding additional column information. The code is the
171+
start column divided by 8 (and rounded down).
136172

137-
Codes 0-9 are the short forms. The short form consists of two bytes, the second byte holding additional column information. The code is the start column divided by 8 (and rounded down).
138173
* Start column: `(code*8) + ((second_byte>>4)&7)`
139174
* End column: `start_column + (second_byte&15)`

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)

0 commit comments

Comments
 (0)