Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f6f52bc

Browse files
committed
Merge branch 'python:main' into main
2 parents 7fbd458 + c51b560 commit f6f52bc

43 files changed

Lines changed: 759 additions & 155 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/CODEOWNERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Makefile.pre.in @erlend-aasland
1717
Modules/Setup* @erlend-aasland
1818

1919
# asyncio
20-
**/*asyncio* @1st1 @asvetlov @gvanrossum @kumaraditya303 @willingc
20+
**/*asyncio* @1st1 @asvetlov @kumaraditya303 @willingc
2121

2222
# Core
2323
**/*context* @1st1
@@ -281,4 +281,4 @@ Lib/test/test_configparser.py @jaraco
281281
# Doc sections
282282
Doc/reference/ @willingc
283283

284-
**/*weakref* @kumaraditya303
284+
**/*weakref* @kumaraditya303

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
# reproducible: to get the same tools versions (autoconf, aclocal, ...)
4747
runs-on: ubuntu-24.04
4848
container:
49-
image: ghcr.io/python/autoconf:2024.10.11.11293396815
49+
image: ghcr.io/python/autoconf:2024.10.16.11360930377
5050
timeout-minutes: 60
5151
needs: check_source
5252
if: needs.check_source.outputs.run_tests == 'true'

Doc/c-api/type.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,20 @@ The following functions and structs are used to create
413413
Creating classes whose metaclass overrides
414414
:c:member:`~PyTypeObject.tp_new` is no longer allowed.
415415
416+
.. c:function:: int PyType_Freeze(PyTypeObject *type)
417+
418+
Make a type immutable: set the :c:macro:`Py_TPFLAGS_IMMUTABLETYPE` flag.
419+
420+
All base classes of *type* must be immutable.
421+
422+
On success, return ``0``.
423+
On error, set an exception and return ``-1``.
424+
425+
The type must not be used before it's made immutable. For example, type
426+
instances must not be created before the type is made immutable.
427+
428+
.. versionadded:: 3.14
429+
416430
.. raw:: html
417431
418432
<!-- Keep old URL fragments working (see gh-97908) -->

Doc/data/stable_abi.dat

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/library/argparse.rst

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,21 @@ how the command-line arguments should be handled. The supplied actions are:
741741
>>> parser.parse_args('--str --int'.split())
742742
Namespace(types=[<class 'str'>, <class 'int'>])
743743

744+
* ``'extend'`` - This stores a list and appends each item from the multi-value
745+
argument list to it.
746+
The ``'extend'`` action is typically used with the nargs_ keyword argument
747+
value ``'+'`` or ``'*'``.
748+
Note that when nargs_ is ``None`` (the default) or ``'?'``, each
749+
character of the argument string will be appended to the list.
750+
Example usage::
751+
752+
>>> parser = argparse.ArgumentParser()
753+
>>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
754+
>>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
755+
Namespace(foo=['f1', 'f2', 'f3', 'f4'])
756+
757+
.. versionadded:: 3.8
758+
744759
* ``'count'`` - This counts the number of times a keyword argument occurs. For
745760
example, this is useful for increasing verbosity levels::
746761

@@ -766,17 +781,6 @@ how the command-line arguments should be handled. The supplied actions are:
766781
>>> parser.parse_args(['--version'])
767782
PROG 2.0
768783

769-
* ``'extend'`` - This stores a list, and extends each argument value to the
770-
list.
771-
Example usage::
772-
773-
>>> parser = argparse.ArgumentParser()
774-
>>> parser.add_argument("--foo", action="extend", nargs="+", type=str)
775-
>>> parser.parse_args(["--foo", "f1", "--foo", "f2", "f3", "f4"])
776-
Namespace(foo=['f1', 'f2', 'f3', 'f4'])
777-
778-
.. versionadded:: 3.8
779-
780784
Only actions that consume command-line arguments (e.g. ``'store'``,
781785
``'append'`` or ``'extend'``) can be used with positional arguments.
782786

Doc/library/ctypes.rst

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -397,15 +397,15 @@ as calling functions with a fixed number of parameters. On some platforms, and i
397397
particular ARM64 for Apple Platforms, the calling convention for variadic functions
398398
is different than that for regular functions.
399399

400-
On those platforms it is required to specify the :attr:`~_FuncPtr.argtypes`
400+
On those platforms it is required to specify the :attr:`~_CFuncPtr.argtypes`
401401
attribute for the regular, non-variadic, function arguments:
402402

403403
.. code-block:: python3
404404
405405
libc.printf.argtypes = [ctypes.c_char_p]
406406
407407
Because specifying the attribute does not inhibit portability it is advised to always
408-
specify :attr:`~_FuncPtr.argtypes` for all variadic functions.
408+
specify :attr:`~_CFuncPtr.argtypes` for all variadic functions.
409409

410410

411411
.. _ctypes-calling-functions-with-own-custom-data-types:
@@ -440,9 +440,9 @@ Specifying the required argument types (function prototypes)
440440
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
441441

442442
It is possible to specify the required argument types of functions exported from
443-
DLLs by setting the :attr:`~_FuncPtr.argtypes` attribute.
443+
DLLs by setting the :attr:`~_CFuncPtr.argtypes` attribute.
444444

445-
:attr:`~_FuncPtr.argtypes` must be a sequence of C data types (the :func:`!printf` function is
445+
:attr:`~_CFuncPtr.argtypes` must be a sequence of C data types (the :func:`!printf` function is
446446
probably not a good example here, because it takes a variable number and
447447
different types of parameters depending on the format string, on the other hand
448448
this is quite handy to experiment with this feature)::
@@ -467,7 +467,7 @@ prototype for a C function), and tries to convert the arguments to valid types::
467467

468468
If you have defined your own classes which you pass to function calls, you have
469469
to implement a :meth:`~_CData.from_param` class method for them to be able to use them
470-
in the :attr:`~_FuncPtr.argtypes` sequence. The :meth:`~_CData.from_param` class method receives
470+
in the :attr:`~_CFuncPtr.argtypes` sequence. The :meth:`~_CData.from_param` class method receives
471471
the Python object passed to the function call, it should do a typecheck or
472472
whatever is needed to make sure this object is acceptable, and then return the
473473
object itself, its :attr:`!_as_parameter_` attribute, or whatever you want to
@@ -490,7 +490,7 @@ Return types
490490

491491

492492
By default functions are assumed to return the C :c:expr:`int` type. Other
493-
return types can be specified by setting the :attr:`~_FuncPtr.restype` attribute of the
493+
return types can be specified by setting the :attr:`~_CFuncPtr.restype` attribute of the
494494
function object.
495495

496496
The C prototype of :c:func:`time` is ``time_t time(time_t *)``. Because :c:type:`time_t`
@@ -499,7 +499,7 @@ specify the :attr:`!restype` attribute::
499499

500500
>>> libc.time.restype = c_time_t
501501

502-
The argument types can be specified using :attr:`~_FuncPtr.argtypes`::
502+
The argument types can be specified using :attr:`~_CFuncPtr.argtypes`::
503503

504504
>>> libc.time.argtypes = (POINTER(c_time_t),)
505505

@@ -522,7 +522,7 @@ a string pointer and a char, and returns a pointer to a string::
522522
>>>
523523

524524
If you want to avoid the :func:`ord("x") <ord>` calls above, you can set the
525-
:attr:`~_FuncPtr.argtypes` attribute, and the second argument will be converted from a
525+
:attr:`~_CFuncPtr.argtypes` attribute, and the second argument will be converted from a
526526
single character Python bytes object into a C char:
527527

528528
.. doctest::
@@ -541,7 +541,7 @@ single character Python bytes object into a C char:
541541
>>>
542542

543543
You can also use a callable Python object (a function or a class for example) as
544-
the :attr:`~_FuncPtr.restype` attribute, if the foreign function returns an integer. The
544+
the :attr:`~_CFuncPtr.restype` attribute, if the foreign function returns an integer. The
545545
callable will be called with the *integer* the C function returns, and the
546546
result of this call will be used as the result of your function call. This is
547547
useful to check for error return values and automatically raise an exception::
@@ -569,7 +569,7 @@ get the string representation of an error code, and *returns* an exception.
569569
:func:`GetLastError` to retrieve it.
570570

571571
Please note that a much more powerful error checking mechanism is available
572-
through the :attr:`~_FuncPtr.errcheck` attribute;
572+
through the :attr:`~_CFuncPtr.errcheck` attribute;
573573
see the reference manual for details.
574574

575575

@@ -877,7 +877,7 @@ Type conversions
877877
^^^^^^^^^^^^^^^^
878878

879879
Usually, ctypes does strict type checking. This means, if you have
880-
``POINTER(c_int)`` in the :attr:`~_FuncPtr.argtypes` list of a function or as the type of
880+
``POINTER(c_int)`` in the :attr:`~_CFuncPtr.argtypes` list of a function or as the type of
881881
a member field in a structure definition, only instances of exactly the same
882882
type are accepted. There are some exceptions to this rule, where ctypes accepts
883883
other objects. For example, you can pass compatible array instances instead of
@@ -898,7 +898,7 @@ pointer types. So, for ``POINTER(c_int)``, ctypes accepts an array of c_int::
898898
>>>
899899

900900
In addition, if a function argument is explicitly declared to be a pointer type
901-
(such as ``POINTER(c_int)``) in :attr:`~_FuncPtr.argtypes`, an object of the pointed
901+
(such as ``POINTER(c_int)``) in :attr:`~_CFuncPtr.argtypes`, an object of the pointed
902902
type (``c_int`` in this case) can be passed to the function. ctypes will apply
903903
the required :func:`byref` conversion in this case automatically.
904904

@@ -1627,10 +1627,20 @@ As explained in the previous section, foreign functions can be accessed as
16271627
attributes of loaded shared libraries. The function objects created in this way
16281628
by default accept any number of arguments, accept any ctypes data instances as
16291629
arguments, and return the default result type specified by the library loader.
1630-
They are instances of a private class:
16311630

1631+
They are instances of a private local class :class:`!_FuncPtr` (not exposed
1632+
in :mod:`!ctypes`) which inherits from the private :class:`_CFuncPtr` class:
16321633

1633-
.. class:: _FuncPtr
1634+
.. doctest::
1635+
1636+
>>> import ctypes
1637+
>>> lib = ctypes.CDLL(None)
1638+
>>> issubclass(lib._FuncPtr, ctypes._CFuncPtr)
1639+
True
1640+
>>> lib._FuncPtr is ctypes._CFuncPtr
1641+
False
1642+
1643+
.. class:: _CFuncPtr
16341644

16351645
Base class for C callable foreign functions.
16361646

@@ -1796,7 +1806,7 @@ different ways, depending on the type and number of the parameters in the call:
17961806
The optional *paramflags* parameter creates foreign function wrappers with much
17971807
more functionality than the features described above.
17981808

1799-
*paramflags* must be a tuple of the same length as :attr:`~_FuncPtr.argtypes`.
1809+
*paramflags* must be a tuple of the same length as :attr:`~_CFuncPtr.argtypes`.
18001810

18011811
Each item in this tuple contains further information about a parameter, it must
18021812
be a tuple containing one, two, or three items.
@@ -1867,7 +1877,7 @@ value if there is a single one, or a tuple containing the output parameter
18671877
values when there are more than one, so the GetWindowRect function now returns a
18681878
RECT instance, when called.
18691879

1870-
Output parameters can be combined with the :attr:`~_FuncPtr.errcheck` protocol to do
1880+
Output parameters can be combined with the :attr:`~_CFuncPtr.errcheck` protocol to do
18711881
further output processing and error checking. The win32 ``GetWindowRect`` api
18721882
function returns a ``BOOL`` to signal success or failure, so this function could
18731883
do the error checking, and raises an exception when the api call failed::
@@ -1880,7 +1890,7 @@ do the error checking, and raises an exception when the api call failed::
18801890
>>> GetWindowRect.errcheck = errcheck
18811891
>>>
18821892

1883-
If the :attr:`~_FuncPtr.errcheck` function returns the argument tuple it receives
1893+
If the :attr:`~_CFuncPtr.errcheck` function returns the argument tuple it receives
18841894
unchanged, :mod:`ctypes` continues the normal processing it does on the output
18851895
parameters. If you want to return a tuple of window coordinates instead of a
18861896
``RECT`` instance, you can retrieve the fields in the function and return them
@@ -2180,7 +2190,7 @@ Data types
21802190

21812191
This method adapts *obj* to a ctypes type. It is called with the actual
21822192
object used in a foreign function call when the type is present in the
2183-
foreign function's :attr:`~_FuncPtr.argtypes` tuple;
2193+
foreign function's :attr:`~_CFuncPtr.argtypes` tuple;
21842194
it must return an object that can be used as a function call parameter.
21852195

21862196
All ctypes data types have a default implementation of this classmethod
@@ -2246,7 +2256,7 @@ Fundamental data types
22462256
Fundamental data types, when returned as foreign function call results, or, for
22472257
example, by retrieving structure field members or array items, are transparently
22482258
converted to native Python types. In other words, if a foreign function has a
2249-
:attr:`~_FuncPtr.restype` of :class:`c_char_p`, you will always receive a Python bytes
2259+
:attr:`~_CFuncPtr.restype` of :class:`c_char_p`, you will always receive a Python bytes
22502260
object, *not* a :class:`c_char_p` instance.
22512261

22522262
.. XXX above is false, it actually returns a Unicode string

Doc/tutorial/errors.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ A more complicated example::
464464
executing finally clause
465465
Traceback (most recent call last):
466466
File "<stdin>", line 1, in <module>
467-
divide("2", "0")
467+
divide("2", "1")
468468
~~~~~~^^^^^^^^^^
469469
File "<stdin>", line 3, in divide
470470
result = x / y

Doc/whatsnew/3.14.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ New features
777777
(Contributed by Victor Stinner in :gh:`124502`.)
778778

779779

780+
* Add :c:func:`PyType_Freeze` function to make a type immutable.
781+
(Contributed by Victor Stinner in :gh:`121654`.)
782+
780783
Porting to Python 3.14
781784
----------------------
782785

Include/object.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,10 @@ static inline int PyType_CheckExact(PyObject *op) {
796796
PyAPI_FUNC(PyObject *) PyType_GetModuleByDef(PyTypeObject *, PyModuleDef *);
797797
#endif
798798

799+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030e0000
800+
PyAPI_FUNC(int) PyType_Freeze(PyTypeObject *type);
801+
#endif
802+
799803
#ifdef __cplusplus
800804
}
801805
#endif

Lib/code.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ def _showtraceback(self, typ, value, tb, source):
136136
# Set the line of text that the exception refers to
137137
lines = source.splitlines()
138138
if (source and typ is SyntaxError
139-
and not value.text and len(lines) >= value.lineno):
139+
and not value.text and value.lineno is not None
140+
and len(lines) >= value.lineno):
140141
value.text = lines[value.lineno - 1]
141142
sys.last_exc = sys.last_value = value
142143
if sys.excepthook is sys.__excepthook__:

0 commit comments

Comments
 (0)