Skip to content

Commit 11c891d

Browse files
committed
Merge branch 'main' into csv-sniffer-counter-set
* main: pythongh-137288: Update 3.14 magic numbers (pythonGH-137665) pythongh-135228: When @DataClass(slots=True) replaces a dataclass, make the original class collectible (take 2) (pythonGH-137047) pythongh-126008: Improve docstrings for Tkinter cget and configure methods (pythonGH-133303) pythongh-131885: Use positional-only markers for ``max()`` and ``min()`` (python#131868) pythonGH-137426: Remove code deprecation of `importlib.abc.ResourceLoader` (pythonGH-137567) pythongh-125897: Mark range function parameters as positional only (python#125945) pythongh-137400: Fix a crash when disabling profiling across all threads (pythongh-137471) pythongh-115766: Fix IPv4Interface.is_unspecified (pythonGH-137326) pythongh-128813: cleanup C-API docs for PyComplexObject (pythonGH-137579) pythongh-135953: Profile a module or script with sampling profiler (python#136777) Fix documentation of hash in PyHash_FuncDef (python#137595)
2 parents 2f1ea73 + 715647a commit 11c891d

26 files changed

+1232
-311
lines changed

Doc/c-api/complex.rst

Lines changed: 103 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -3,116 +3,10 @@
33
.. _complexobjects:
44

55
Complex Number Objects
6-
----------------------
6+
======================
77

88
.. index:: pair: object; complex number
99

10-
Python's complex number objects are implemented as two distinct types when
11-
viewed from the C API: one is the Python object exposed to Python programs, and
12-
the other is a C structure which represents the actual complex number value.
13-
The API provides functions for working with both.
14-
15-
16-
Complex Numbers as C Structures
17-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18-
19-
Note that the functions which accept these structures as parameters and return
20-
them as results do so *by value* rather than dereferencing them through
21-
pointers. This is consistent throughout the API.
22-
23-
24-
.. c:type:: Py_complex
25-
26-
The C structure which corresponds to the value portion of a Python complex
27-
number object. Most of the functions for dealing with complex number objects
28-
use structures of this type as input or output values, as appropriate.
29-
30-
.. c:member:: double real
31-
double imag
32-
33-
The structure is defined as::
34-
35-
typedef struct {
36-
double real;
37-
double imag;
38-
} Py_complex;
39-
40-
41-
.. c:function:: Py_complex _Py_c_sum(Py_complex left, Py_complex right)
42-
43-
Return the sum of two complex numbers, using the C :c:type:`Py_complex`
44-
representation.
45-
46-
.. deprecated:: 3.15
47-
This function is :term:`soft deprecated`.
48-
49-
50-
.. c:function:: Py_complex _Py_c_diff(Py_complex left, Py_complex right)
51-
52-
Return the difference between two complex numbers, using the C
53-
:c:type:`Py_complex` representation.
54-
55-
.. deprecated:: 3.15
56-
This function is :term:`soft deprecated`.
57-
58-
59-
.. c:function:: Py_complex _Py_c_neg(Py_complex num)
60-
61-
Return the negation of the complex number *num*, using the C
62-
:c:type:`Py_complex` representation.
63-
64-
.. deprecated:: 3.15
65-
This function is :term:`soft deprecated`.
66-
67-
68-
.. c:function:: Py_complex _Py_c_prod(Py_complex left, Py_complex right)
69-
70-
Return the product of two complex numbers, using the C :c:type:`Py_complex`
71-
representation.
72-
73-
.. deprecated:: 3.15
74-
This function is :term:`soft deprecated`.
75-
76-
77-
.. c:function:: Py_complex _Py_c_quot(Py_complex dividend, Py_complex divisor)
78-
79-
Return the quotient of two complex numbers, using the C :c:type:`Py_complex`
80-
representation.
81-
82-
If *divisor* is null, this method returns zero and sets
83-
:c:data:`errno` to :c:macro:`!EDOM`.
84-
85-
.. deprecated:: 3.15
86-
This function is :term:`soft deprecated`.
87-
88-
89-
.. c:function:: Py_complex _Py_c_pow(Py_complex num, Py_complex exp)
90-
91-
Return the exponentiation of *num* by *exp*, using the C :c:type:`Py_complex`
92-
representation.
93-
94-
If *num* is null and *exp* is not a positive real number,
95-
this method returns zero and sets :c:data:`errno` to :c:macro:`!EDOM`.
96-
97-
Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows.
98-
99-
.. deprecated:: 3.15
100-
This function is :term:`soft deprecated`.
101-
102-
103-
.. c:function:: double _Py_c_abs(Py_complex num)
104-
105-
Return the absolute value of the complex number *num*.
106-
107-
Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows.
108-
109-
.. deprecated:: 3.15
110-
This function is :term:`soft deprecated`.
111-
112-
113-
Complex Numbers as Python Objects
114-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
115-
11610

11711
.. c:type:: PyComplexObject
11812
@@ -147,12 +41,6 @@ Complex Numbers as Python Objects
14741
:c:type:`PyComplexObject`. This function always succeeds.
14842
14943
150-
.. c:function:: PyObject* PyComplex_FromCComplex(Py_complex v)
151-
152-
Create a new Python complex number object from a C :c:type:`Py_complex` value.
153-
Return ``NULL`` with an exception set on error.
154-
155-
15644
.. c:function:: PyObject* PyComplex_FromDoubles(double real, double imag)
15745
15846
Return a new :c:type:`PyComplexObject` object from *real* and *imag*.
@@ -191,6 +79,29 @@ Complex Numbers as Python Objects
19179
.. versionchanged:: 3.13
19280
Use :meth:`~object.__complex__` if available.
19381
82+
83+
.. c:type:: Py_complex
84+
85+
This C structure defines export format for a Python complex
86+
number object.
87+
88+
.. c:member:: double real
89+
double imag
90+
91+
The structure is defined as::
92+
93+
typedef struct {
94+
double real;
95+
double imag;
96+
} Py_complex;
97+
98+
99+
.. c:function:: PyObject* PyComplex_FromCComplex(Py_complex v)
100+
101+
Create a new Python complex number object from a C :c:type:`Py_complex` value.
102+
Return ``NULL`` with an exception set on error.
103+
104+
194105
.. c:function:: Py_complex PyComplex_AsCComplex(PyObject *op)
195106
196107
Return the :c:type:`Py_complex` value of the complex number *op*.
@@ -207,3 +118,82 @@ Complex Numbers as Python Objects
207118
208119
.. versionchanged:: 3.8
209120
Use :meth:`~object.__index__` if available.
121+
122+
123+
Complex Numbers as C Structures
124+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
125+
126+
The API also provides functions for working with complex numbers, using the
127+
:c:type:`Py_complex` representation. Note that the functions which accept
128+
these structures as parameters and return them as results do so *by value*
129+
rather than dereferencing them through pointers.
130+
131+
Please note, that these functions are :term:`soft deprecated` since Python
132+
3.15. Avoid using this API in a new code to do complex arithmetic: either use
133+
the `Number Protocol <number>`_ API or use native complex types, like
134+
:c:expr:`double complex`.
135+
136+
137+
.. c:function:: Py_complex _Py_c_sum(Py_complex left, Py_complex right)
138+
139+
Return the sum of two complex numbers, using the C :c:type:`Py_complex`
140+
representation.
141+
142+
.. deprecated:: 3.15
143+
144+
145+
.. c:function:: Py_complex _Py_c_diff(Py_complex left, Py_complex right)
146+
147+
Return the difference between two complex numbers, using the C
148+
:c:type:`Py_complex` representation.
149+
150+
.. deprecated:: 3.15
151+
152+
153+
.. c:function:: Py_complex _Py_c_neg(Py_complex num)
154+
155+
Return the negation of the complex number *num*, using the C
156+
:c:type:`Py_complex` representation.
157+
158+
.. deprecated:: 3.15
159+
160+
161+
.. c:function:: Py_complex _Py_c_prod(Py_complex left, Py_complex right)
162+
163+
Return the product of two complex numbers, using the C :c:type:`Py_complex`
164+
representation.
165+
166+
.. deprecated:: 3.15
167+
168+
169+
.. c:function:: Py_complex _Py_c_quot(Py_complex dividend, Py_complex divisor)
170+
171+
Return the quotient of two complex numbers, using the C :c:type:`Py_complex`
172+
representation.
173+
174+
If *divisor* is null, this method returns zero and sets
175+
:c:data:`errno` to :c:macro:`!EDOM`.
176+
177+
.. deprecated:: 3.15
178+
179+
180+
.. c:function:: Py_complex _Py_c_pow(Py_complex num, Py_complex exp)
181+
182+
Return the exponentiation of *num* by *exp*, using the C :c:type:`Py_complex`
183+
representation.
184+
185+
If *num* is null and *exp* is not a positive real number,
186+
this method returns zero and sets :c:data:`errno` to :c:macro:`!EDOM`.
187+
188+
Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows.
189+
190+
.. deprecated:: 3.15
191+
192+
193+
.. c:function:: double _Py_c_abs(Py_complex num)
194+
195+
Return the absolute value of the complex number *num*.
196+
197+
Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows.
198+
199+
.. deprecated:: 3.15

Doc/c-api/hash.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ See also the :c:member:`PyTypeObject.tp_hash` member and :ref:`numeric-hash`.
5151
5252
Hash function definition used by :c:func:`PyHash_GetFuncDef`.
5353

54-
.. c::member:: Py_hash_t (*const hash)(const void *, Py_ssize_t)
54+
.. c:member:: Py_hash_t (*const hash)(const void *, Py_ssize_t)
5555
5656
Hash function.
5757

Doc/library/functions.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,9 +1220,9 @@ are always available. They are listed here in alphabetical order.
12201220
Added the *strict* parameter.
12211221

12221222

1223-
.. function:: max(iterable, *, key=None)
1224-
max(iterable, *, default, key=None)
1225-
max(arg1, arg2, *args, key=None)
1223+
.. function:: max(iterable, /, *, key=None)
1224+
max(iterable, /, *, default, key=None)
1225+
max(arg1, arg2, /, *args, key=None)
12261226
12271227
Return the largest item in an iterable or the largest of two or more
12281228
arguments.
@@ -1258,9 +1258,9 @@ are always available. They are listed here in alphabetical order.
12581258
:ref:`typememoryview` for more information.
12591259

12601260

1261-
.. function:: min(iterable, *, key=None)
1262-
min(iterable, *, default, key=None)
1263-
min(arg1, arg2, *args, key=None)
1261+
.. function:: min(iterable, /, *, key=None)
1262+
min(iterable, /, *, default, key=None)
1263+
min(arg1, arg2, /, *args, key=None)
12641264
12651265
Return the smallest item in an iterable or the smallest of two or more
12661266
arguments.
@@ -1729,8 +1729,8 @@ are always available. They are listed here in alphabetical order.
17291729

17301730

17311731
.. _func-range:
1732-
.. class:: range(stop)
1733-
range(start, stop, step=1)
1732+
.. class:: range(stop, /)
1733+
range(start, stop, step=1, /)
17341734
:noindex:
17351735

17361736
Rather than being a function, :class:`range` is actually an immutable

Doc/library/importlib.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,8 @@ ABC hierarchy::
393393
.. deprecated:: 3.7
394394
This ABC is deprecated in favour of supporting resource loading
395395
through :class:`importlib.resources.abc.TraversableResources`.
396+
This class exists for backwards compatibility only with other ABCs in
397+
this module.
396398

397399
.. method:: get_data(path)
398400
:abstractmethod:

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ Known values:
277277
Python 3.14a7 3622 (Store annotations in different class dict keys)
278278
Python 3.14a7 3623 (Add BUILD_INTERPOLATION & BUILD_TEMPLATE opcodes)
279279
Python 3.14b1 3624 (Don't optimize LOAD_FAST when local is killed by DELETE_FAST)
280+
Python 3.14b3 3625 (Fix handling of opcodes that may leave operands on the stack when optimizing LOAD_FAST)
281+
Python 3.14rc2 3626 (Fix missing exception handlers in logical expression)
280282
Python 3.15a0 3650 (Initial version)
281283
Python 3.15a1 3651 (Simplify LOAD_CONST)
282284
Python 3.15a1 3652 (Virtual iterators)

Lib/dataclasses.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,10 @@ def _add_slots(cls, is_frozen, weakref_slot, defined_fields):
12831283
if '__slots__' in cls.__dict__:
12841284
raise TypeError(f'{cls.__name__} already specifies __slots__')
12851285

1286+
# gh-102069: Remove existing __weakref__ descriptor.
1287+
# gh-135228: Make sure the original class can be garbage collected.
1288+
sys._clear_type_descriptors(cls)
1289+
12861290
# Create a new dict for our new class.
12871291
cls_dict = dict(cls.__dict__)
12881292
field_names = tuple(f.name for f in fields(cls))
@@ -1300,12 +1304,6 @@ def _add_slots(cls, is_frozen, weakref_slot, defined_fields):
13001304
# available in _MARKER.
13011305
cls_dict.pop(field_name, None)
13021306

1303-
# Remove __dict__ itself.
1304-
cls_dict.pop('__dict__', None)
1305-
1306-
# Clear existing `__weakref__` descriptor, it belongs to a previous type:
1307-
cls_dict.pop('__weakref__', None) # gh-102069
1308-
13091307
# And finally create the class.
13101308
qualname = getattr(cls, '__qualname__', None)
13111309
newcls = type(cls)(cls.__name__, cls.__bases__, cls_dict)

Lib/importlib/abc.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,14 @@ def invalidate_caches(self):
6464
class ResourceLoader(Loader):
6565

6666
"""Abstract base class for loaders which can return data from their
67-
back-end storage.
67+
back-end storage to facilitate reading data to perform an import.
6868
6969
This ABC represents one of the optional protocols specified by PEP 302.
7070
71-
"""
72-
73-
def __init__(self):
74-
import warnings
75-
warnings.warn('importlib.abc.ResourceLoader is deprecated in '
76-
'favour of supporting resource loading through '
77-
'importlib.resources.abc.TraversableResources.',
78-
DeprecationWarning, stacklevel=2)
79-
super().__init__()
71+
For directly loading resources, use TraversableResources instead. This class
72+
primarily exists for backwards compatibility with other ABCs in this module.
8073
74+
"""
8175

8276
@abc.abstractmethod
8377
def get_data(self, path):

Lib/ipaddress.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,6 +1479,10 @@ def with_hostmask(self):
14791479
return '%s/%s' % (self._string_from_ip_int(self._ip),
14801480
self.hostmask)
14811481

1482+
@property
1483+
def is_unspecified(self):
1484+
return self._ip == 0 and self.network.is_unspecified
1485+
14821486

14831487
class IPv4Network(_BaseV4, _BaseNetwork):
14841488

0 commit comments

Comments
 (0)