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

Skip to content

Commit 2a60cc8

Browse files
Merge branch 'main' into complex-constructor
2 parents 90029cf + 1c04c63 commit 2a60cc8

File tree

183 files changed

+7016
-2810
lines changed

Some content is hidden

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

183 files changed

+7016
-2810
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ jobs:
388388
id: cache-hypothesis-database
389389
uses: actions/cache@v4
390390
with:
391-
path: ./hypothesis
391+
path: ${{ env.CPYTHON_BUILDDIR }}/.hypothesis/
392392
key: hypothesis-database-${{ github.head_ref || github.run_id }}
393393
restore-keys: |
394394
- hypothesis-database-
@@ -416,7 +416,7 @@ jobs:
416416
if: always()
417417
with:
418418
name: hypothesis-example-db
419-
path: .hypothesis/examples/
419+
path: ${{ env.CPYTHON_BUILDDIR }}/.hypothesis/examples/
420420

421421

422422
build_asan:

Doc/faq/library.rst

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -541,84 +541,6 @@ Thus, to read *n* bytes from a pipe *p* created with :func:`os.popen`, you need
541541
use ``p.read(n)``.
542542
543543
544-
.. XXX update to use subprocess. See the :ref:`subprocess-replacements` section.
545-
546-
How do I run a subprocess with pipes connected to both input and output?
547-
------------------------------------------------------------------------
548-
549-
Use the :mod:`popen2` module. For example::
550-
551-
import popen2
552-
fromchild, tochild = popen2.popen2("command")
553-
tochild.write("input\n")
554-
tochild.flush()
555-
output = fromchild.readline()
556-
557-
Warning: in general it is unwise to do this because you can easily cause a
558-
deadlock where your process is blocked waiting for output from the child
559-
while the child is blocked waiting for input from you. This can be caused
560-
by the parent expecting the child to output more text than it does or
561-
by data being stuck in stdio buffers due to lack of flushing.
562-
The Python parent can of course explicitly flush the data it sends to the
563-
child before it reads any output, but if the child is a naive C program it
564-
may have been written to never explicitly flush its output, even if it is
565-
interactive, since flushing is normally automatic.
566-
567-
Note that a deadlock is also possible if you use :func:`popen3` to read
568-
stdout and stderr. If one of the two is too large for the internal buffer
569-
(increasing the buffer size does not help) and you ``read()`` the other one
570-
first, there is a deadlock, too.
571-
572-
Note on a bug in popen2: unless your program calls ``wait()`` or
573-
``waitpid()``, finished child processes are never removed, and eventually
574-
calls to popen2 will fail because of a limit on the number of child
575-
processes. Calling :func:`os.waitpid` with the :const:`os.WNOHANG` option can
576-
prevent this; a good place to insert such a call would be before calling
577-
``popen2`` again.
578-
579-
In many cases, all you really need is to run some data through a command and
580-
get the result back. Unless the amount of data is very large, the easiest
581-
way to do this is to write it to a temporary file and run the command with
582-
that temporary file as input. The standard module :mod:`tempfile` exports a
583-
:func:`~tempfile.mktemp` function to generate unique temporary file names. ::
584-
585-
import tempfile
586-
import os
587-
588-
class Popen3:
589-
"""
590-
This is a deadlock-safe version of popen that returns
591-
an object with errorlevel, out (a string) and err (a string).
592-
(capturestderr may not work under windows.)
593-
Example: print(Popen3('grep spam','\n\nhere spam\n\n').out)
594-
"""
595-
def __init__(self,command,input=None,capturestderr=None):
596-
outfile=tempfile.mktemp()
597-
command="( %s ) > %s" % (command,outfile)
598-
if input:
599-
infile=tempfile.mktemp()
600-
open(infile,"w").write(input)
601-
command=command+" <"+infile
602-
if capturestderr:
603-
errfile=tempfile.mktemp()
604-
command=command+" 2>"+errfile
605-
self.errorlevel=os.system(command) >> 8
606-
self.out=open(outfile,"r").read()
607-
os.remove(outfile)
608-
if input:
609-
os.remove(infile)
610-
if capturestderr:
611-
self.err=open(errfile,"r").read()
612-
os.remove(errfile)
613-
614-
Note that many interactive programs (e.g. vi) don't work well with pipes
615-
substituted for standard input and output. You will have to use pseudo ttys
616-
("ptys") instead of pipes. Or you can use a Python interface to Don Libes'
617-
"expect" library. A Python extension that interfaces to expect is called
618-
"expy" and available from https://expectpy.sourceforge.net. A pure Python
619-
solution that works like expect is :pypi:`pexpect`.
620-
621-
622544
How do I access the serial (RS232) port?
623545
----------------------------------------
624546

Doc/glossary.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,11 +425,11 @@ Glossary
425425
An object that tries to find the :term:`loader` for a module that is
426426
being imported.
427427

428-
Since Python 3.3, there are two types of finder: :term:`meta path finders
428+
There are two types of finder: :term:`meta path finders
429429
<meta path finder>` for use with :data:`sys.meta_path`, and :term:`path
430430
entry finders <path entry finder>` for use with :data:`sys.path_hooks`.
431431

432-
See :pep:`302`, :pep:`420` and :pep:`451` for much more detail.
432+
See :ref:`importsystem` and :mod:`importlib` for much more detail.
433433

434434
floor division
435435
Mathematical division that rounds down to nearest integer. The floor

Doc/howto/pyporting.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ please see :ref:`cporting-howto`.
1818

1919
The archived python-porting_ mailing list may contain some useful guidance.
2020

21-
Since Python 3.13 the original porting guide was discontinued.
21+
Since Python 3.11 the original porting guide was discontinued.
2222
You can find the old guide in the
23-
`archive <https://docs.python.org/3.12/howto/pyporting.html>`_.
23+
`archive <https://docs.python.org/3.10/howto/pyporting.html>`_.
2424

2525

2626
Third-party guides

Doc/library/ctypes.rst

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,18 @@ for debugging because they can provide useful information::
661661
guaranteed by the library to work in the general case. Unions and
662662
structures with bit-fields should always be passed to functions by pointer.
663663

664-
Structure/union alignment and byte order
665-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
666-
667-
By default, Structure and Union fields are aligned in the same way the C
668-
compiler does it. It is possible to override this behavior by specifying a
669-
:attr:`~Structure._pack_` class attribute in the subclass definition.
670-
This must be set to a positive integer and specifies the maximum alignment for the fields.
671-
This is what ``#pragma pack(n)`` also does in MSVC.
664+
Structure/union layout, alignment and byte order
665+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
666+
667+
By default, Structure and Union fields are laid out in the same way the C
668+
compiler does it. It is possible to override this behavior entirely by specifying a
669+
:attr:`~Structure._layout_` class attribute in the subclass definition; see
670+
the attribute documentation for details.
671+
672+
It is possible to specify the maximum alignment for the fields by setting
673+
the :attr:`~Structure._pack_` class attribute to a positive integer.
674+
This matches what ``#pragma pack(n)`` does in MSVC.
675+
672676
It is also possible to set a minimum alignment for how the subclass itself is packed in the
673677
same way ``#pragma align(n)`` works in MSVC.
674678
This can be achieved by specifying a ::attr:`~Structure._align_` class attribute
@@ -2540,6 +2544,31 @@ fields, or any other data types containing pointer type fields.
25402544
the structure when being packed or unpacked to/from memory.
25412545
Setting this attribute to 0 is the same as not setting it at all.
25422546

2547+
.. attribute:: _layout_
2548+
2549+
An optional string naming the struct/union layout. It can currently
2550+
be set to:
2551+
2552+
- ``"ms"``: the layout used by the Microsoft compiler (MSVC).
2553+
On GCC and Clang, this layout can be selected with
2554+
``__attribute__((ms_struct))``.
2555+
- ``"gcc-sysv"``: the layout used by GCC with the System V or “SysV-like”
2556+
data model, as used on Linux and macOS.
2557+
With this layout, :attr:`~Structure._pack_` must be unset or zero.
2558+
2559+
If not set explicitly, ``ctypes`` will use a default that
2560+
matches the platform conventions. This default may change in future
2561+
Python releases (for example, when a new platform gains official support,
2562+
or when a difference between similar platforms is found).
2563+
Currently the default will be:
2564+
2565+
- On Windows: ``"ms"``
2566+
- When :attr:`~Structure._pack_` is specified: ``"ms"``
2567+
- Otherwise: ``"gcc-sysv"``
2568+
2569+
:attr:`!_layout_` must already be defined when
2570+
:attr:`~Structure._fields_` is assigned, otherwise it will have no effect.
2571+
25432572
.. attribute:: _anonymous_
25442573

25452574
An optional sequence that lists the names of unnamed (anonymous) fields.

Doc/library/dataclasses.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ Module contents
461461

462462
.. function:: is_dataclass(obj)
463463

464-
Return ``True`` if its parameter is a dataclass or an instance of one,
465-
otherwise return ``False``.
464+
Return ``True`` if its parameter is a dataclass (including subclasses of a
465+
dataclass) or an instance of one, otherwise return ``False``.
466466

467467
If you need to know if a class is an instance of a dataclass (and
468468
not a dataclass itself), then add a further check for ``not

Doc/library/logging.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ The ``name`` is potentially a period-separated hierarchical value, like
109109
Loggers that are further down in the hierarchical list are children of loggers
110110
higher up in the list. For example, given a logger with a name of ``foo``,
111111
loggers with names of ``foo.bar``, ``foo.bar.baz``, and ``foo.bam`` are all
112-
descendants of ``foo``. The logger name hierarchy is analogous to the Python
113-
package hierarchy, and identical to it if you organise your loggers on a
114-
per-module basis using the recommended construction
115-
``logging.getLogger(__name__)``. That's because in a module, ``__name__``
116-
is the module's name in the Python package namespace.
112+
descendants of ``foo``. In addition, all loggers are descendants of the root
113+
logger. The logger name hierarchy is analogous to the Python package hierarchy,
114+
and identical to it if you organise your loggers on a per-module basis using
115+
the recommended construction ``logging.getLogger(__name__)``. That's because
116+
in a module, ``__name__`` is the module's name in the Python package namespace.
117117

118118

119119
.. class:: Logger
@@ -1157,10 +1157,12 @@ functions.
11571157

11581158
.. function:: getLogger(name=None)
11591159

1160-
Return a logger with the specified name or, if name is ``None``, return a
1161-
logger which is the root logger of the hierarchy. If specified, the name is
1162-
typically a dot-separated hierarchical name like *'a'*, *'a.b'* or *'a.b.c.d'*.
1163-
Choice of these names is entirely up to the developer who is using logging.
1160+
Return a logger with the specified name or, if name is ``None``, return the
1161+
root logger of the hierarchy. If specified, the name is typically a
1162+
dot-separated hierarchical name like *'a'*, *'a.b'* or *'a.b.c.d'*. Choice
1163+
of these names is entirely up to the developer who is using logging, though
1164+
it is recommended that ``__name__`` be used unless you have a specific
1165+
reason for not doing that, as mentioned in :ref:`logger`.
11641166

11651167
All calls to this function with a given name return the same logger instance.
11661168
This means that logger instances never need to be passed between different parts

Doc/library/subprocess.rst

Lines changed: 3 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ underlying :class:`Popen` interface can be used directly.
5252

5353
If *capture_output* is true, stdout and stderr will be captured.
5454
When used, the internal :class:`Popen` object is automatically created with
55-
*stdout* and *stdin* both set to :data:`~subprocess.PIPE`.
55+
*stdout* and *stderr* both set to :data:`~subprocess.PIPE`.
5656
The *stdout* and *stderr* arguments may not be supplied at the same time as *capture_output*.
5757
If you wish to capture and combine both streams into one,
5858
set *stdout* to :data:`~subprocess.PIPE`
@@ -1443,36 +1443,8 @@ Environment example::
14431443

14441444

14451445

1446-
Replacing :func:`os.popen`, :func:`os.popen2`, :func:`os.popen3`
1447-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1448-
1449-
::
1450-
1451-
(child_stdin, child_stdout) = os.popen2(cmd, mode, bufsize)
1452-
==>
1453-
p = Popen(cmd, shell=True, bufsize=bufsize,
1454-
stdin=PIPE, stdout=PIPE, close_fds=True)
1455-
(child_stdin, child_stdout) = (p.stdin, p.stdout)
1456-
1457-
::
1458-
1459-
(child_stdin,
1460-
child_stdout,
1461-
child_stderr) = os.popen3(cmd, mode, bufsize)
1462-
==>
1463-
p = Popen(cmd, shell=True, bufsize=bufsize,
1464-
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
1465-
(child_stdin,
1466-
child_stdout,
1467-
child_stderr) = (p.stdin, p.stdout, p.stderr)
1468-
1469-
::
1470-
1471-
(child_stdin, child_stdout_and_stderr) = os.popen4(cmd, mode, bufsize)
1472-
==>
1473-
p = Popen(cmd, shell=True, bufsize=bufsize,
1474-
stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
1475-
(child_stdin, child_stdout_and_stderr) = (p.stdin, p.stdout)
1446+
Replacing :func:`os.popen`
1447+
^^^^^^^^^^^^^^^^^^^^^^^^^^
14761448

14771449
Return code handling translates as follows::
14781450

@@ -1489,44 +1461,6 @@ Return code handling translates as follows::
14891461
print("There were some errors")
14901462

14911463

1492-
Replacing functions from the :mod:`!popen2` module
1493-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1494-
1495-
.. note::
1496-
1497-
If the cmd argument to popen2 functions is a string, the command is executed
1498-
through /bin/sh. If it is a list, the command is directly executed.
1499-
1500-
::
1501-
1502-
(child_stdout, child_stdin) = popen2.popen2("somestring", bufsize, mode)
1503-
==>
1504-
p = Popen("somestring", shell=True, bufsize=bufsize,
1505-
stdin=PIPE, stdout=PIPE, close_fds=True)
1506-
(child_stdout, child_stdin) = (p.stdout, p.stdin)
1507-
1508-
::
1509-
1510-
(child_stdout, child_stdin) = popen2.popen2(["mycmd", "myarg"], bufsize, mode)
1511-
==>
1512-
p = Popen(["mycmd", "myarg"], bufsize=bufsize,
1513-
stdin=PIPE, stdout=PIPE, close_fds=True)
1514-
(child_stdout, child_stdin) = (p.stdout, p.stdin)
1515-
1516-
:class:`popen2.Popen3` and :class:`popen2.Popen4` basically work as
1517-
:class:`subprocess.Popen`, except that:
1518-
1519-
* :class:`Popen` raises an exception if the execution fails.
1520-
1521-
* The *capturestderr* argument is replaced with the *stderr* argument.
1522-
1523-
* ``stdin=PIPE`` and ``stdout=PIPE`` must be specified.
1524-
1525-
* popen2 closes all file descriptors by default, but you have to specify
1526-
``close_fds=True`` with :class:`Popen` to guarantee this behavior on
1527-
all platforms or past Python versions.
1528-
1529-
15301464
Legacy Shell Invocation Functions
15311465
---------------------------------
15321466

Doc/tools/extensions/peg_highlight.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ class PEGLexer(RegexLexer):
1616
- Rule types
1717
- Rule options
1818
- Rules named `invalid_*` or `incorrect_*`
19-
- Rules with `RAISE_SYNTAX_ERROR`
2019
"""
2120

2221
name = "PEG"
@@ -60,7 +59,6 @@ class PEGLexer(RegexLexer):
6059
(r"^(\s+\|\s+.*invalid_\w+.*\n)", bygroups(None)),
6160
(r"^(\s+\|\s+.*incorrect_\w+.*\n)", bygroups(None)),
6261
(r"^(#.*invalid syntax.*(?:.|\n)*)", bygroups(None),),
63-
(r"^(\s+\|\s+.*\{[^}]*RAISE_SYNTAX_ERROR[^}]*\})\n", bygroups(None)),
6462
],
6563
"root": [
6664
include("invalids"),

Doc/whatsnew/3.13.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,18 @@ copy
656656
any user classes which define the :meth:`!__replace__` method.
657657
(Contributed by Serhiy Storchaka in :gh:`108751`.)
658658

659+
ctypes
660+
------
661+
662+
* The layout of :ref:`bit fields <ctypes-bit-fields-in-structures-unions>` in
663+
:class:`~ctypes.Structure` and :class:`~ctypes.Union` was improved to better
664+
match platform defaults (GCC/Clang or MSC). In particular, fields no longer
665+
overlap.
666+
(Contributed by Matthias Görgens in :gh:`97702`.)
667+
* A :attr:`ctypes.Structure._layout_` class attribute can be set
668+
to help match a non-default ABI.
669+
(Contributed by Petr Viktorin in :gh:`97702`.)
670+
659671
dbm
660672
---
661673

@@ -2169,6 +2181,10 @@ Build Changes
21692181
The bundled mimalloc has custom changes, see :gh:`113141` for details.
21702182
(Contributed by Dino Viehland in :gh:`109914`.)
21712183

2184+
* On POSIX systems, the pkg-config (``.pc``) filenames now include the ABI
2185+
flags. For example, the free-threaded build generates ``python-3.13t.pc``
2186+
and the debug build generates ``python-3.13d.pc``.
2187+
21722188

21732189
Porting to Python 3.13
21742190
======================

0 commit comments

Comments
 (0)