Skip to content

Commit 2d5e5d1

Browse files
authored
Merge branch 'main' into complex-cov-tests
2 parents 9b431af + 2e632fa commit 2d5e5d1

Some content is hidden

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

51 files changed

+689
-340
lines changed

Doc/library/getpass.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ The :mod:`getpass` module provides two functions:
4646
:envvar:`USER`, :envvar:`!LNAME` and :envvar:`USERNAME`, in order, and
4747
returns the value of the first one which is set to a non-empty string. If
4848
none are set, the login name from the password database is returned on
49-
systems which support the :mod:`pwd` module, otherwise, an exception is
50-
raised.
49+
systems which support the :mod:`pwd` module, otherwise, an :exc:`OSError`
50+
is raised.
5151

5252
In general, this function should be preferred over :func:`os.getlogin()`.
53+
54+
.. versionchanged:: 3.13
55+
Previously, various exceptions beyond just :exc:`OSError` were raised.

Doc/library/importlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1145,7 +1145,7 @@ find and load modules.
11451145
.. versionadded:: 3.4
11461146

11471147

1148-
.. class:: NamespaceLoader(name, path, path_finder):
1148+
.. class:: NamespaceLoader(name, path, path_finder)
11491149

11501150
A concrete implementation of :class:`importlib.abc.InspectLoader` for
11511151
namespace packages. This is an alias for a private class and is only made

Doc/library/socket.rst

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ all modern Unix systems, Windows, MacOS, and probably additional platforms.
2323

2424
The Python interface is a straightforward transliteration of the Unix system
2525
call and library interface for sockets to Python's object-oriented style: the
26-
:func:`.socket` function returns a :dfn:`socket object` whose methods implement
26+
:func:`~socket.socket` function returns a :dfn:`socket object` whose methods implement
2727
the various socket system calls. Parameter types are somewhat higher-level than
2828
in the C interface: as with :meth:`read` and :meth:`write` operations on Python
2929
files, buffer allocation on receive operations is automatic, and buffer length
@@ -185,15 +185,14 @@ created. Socket addresses are represented as follows:
185185
.. versionadded:: 3.7
186186

187187
- :const:`AF_PACKET` is a low-level interface directly to network devices.
188-
The packets are represented by the tuple
188+
The addresses are represented by the tuple
189189
``(ifname, proto[, pkttype[, hatype[, addr]]])`` where:
190190

191191
- *ifname* - String specifying the device name.
192192
- *proto* - The Ethernet protocol number.
193193
May be :data:`ETH_P_ALL` to capture all protocols,
194194
one of the :ref:`ETHERTYPE_* constants <socket-ethernet-types>`
195195
or any other Ethernet protocol number.
196-
Value must be in network-byte-order.
197196
- *pkttype* - Optional integer specifying the packet type:
198197

199198
- ``PACKET_HOST`` (the default) - Packet addressed to the local host.
@@ -348,7 +347,7 @@ Constants
348347
AF_INET6
349348

350349
These constants represent the address (and protocol) families, used for the
351-
first argument to :func:`.socket`. If the :const:`AF_UNIX` constant is not
350+
first argument to :func:`~socket.socket`. If the :const:`AF_UNIX` constant is not
352351
defined then this protocol is unsupported. More constants may be available
353352
depending on the system.
354353

@@ -365,7 +364,7 @@ Constants
365364
SOCK_SEQPACKET
366365

367366
These constants represent the socket types, used for the second argument to
368-
:func:`.socket`. More constants may be available depending on the system.
367+
:func:`~socket.socket`. More constants may be available depending on the system.
369368
(Only :const:`SOCK_STREAM` and :const:`SOCK_DGRAM` appear to be generally
370369
useful.)
371370

@@ -404,7 +403,7 @@ Constants
404403

405404
Many constants of these forms, documented in the Unix documentation on sockets
406405
and/or the IP protocol, are also defined in the socket module. They are
407-
generally used in arguments to the :meth:`setsockopt` and :meth:`getsockopt`
406+
generally used in arguments to the :meth:`~socket.setsockopt` and :meth:`~socket.getsockopt`
408407
methods of socket objects. In most cases, only those symbols that are defined
409408
in the Unix header files are defined; for a few symbols, default values are
410409
provided.
@@ -770,7 +769,7 @@ The following functions all create :ref:`socket objects <socket-objects>`.
770769

771770
Build a pair of connected socket objects using the given address family, socket
772771
type, and protocol number. Address family, socket type, and protocol number are
773-
as for the :func:`.socket` function above. The default family is :const:`AF_UNIX`
772+
as for the :func:`~socket.socket` function above. The default family is :const:`AF_UNIX`
774773
if defined on the platform; otherwise, the default is :const:`AF_INET`.
775774

776775
The newly created sockets are :ref:`non-inheritable <fd_inheritance>`.
@@ -866,7 +865,7 @@ The following functions all create :ref:`socket objects <socket-objects>`.
866865

867866
Duplicate the file descriptor *fd* (an integer as returned by a file object's
868867
:meth:`~io.IOBase.fileno` method) and build a socket object from the result. Address
869-
family, socket type and protocol number are as for the :func:`.socket` function
868+
family, socket type and protocol number are as for the :func:`~socket.socket` function
870869
above. The file descriptor should refer to a socket, but this is not checked ---
871870
subsequent operations on the object may fail if the file descriptor is invalid.
872871
This function is rarely needed, but can be used to get or set socket options on
@@ -931,7 +930,7 @@ The :mod:`socket` module also offers various network-related services:
931930
``(family, type, proto, canonname, sockaddr)``
932931

933932
In these tuples, *family*, *type*, *proto* are all integers and are
934-
meant to be passed to the :func:`.socket` function. *canonname* will be
933+
meant to be passed to the :func:`~socket.socket` function. *canonname* will be
935934
a string representing the canonical name of the *host* if
936935
:const:`AI_CANONNAME` is part of the *flags* argument; else *canonname*
937936
will be empty. *sockaddr* is a tuple describing a socket address, whose
@@ -1047,7 +1046,7 @@ The :mod:`socket` module also offers various network-related services:
10471046
.. function:: getprotobyname(protocolname)
10481047

10491048
Translate an internet protocol name (for example, ``'icmp'``) to a constant
1050-
suitable for passing as the (optional) third argument to the :func:`.socket`
1049+
suitable for passing as the (optional) third argument to the :func:`~socket.socket`
10511050
function. This is usually only needed for sockets opened in "raw" mode
10521051
(:const:`SOCK_RAW`); for the normal socket modes, the correct protocol is chosen
10531052
automatically if the protocol is omitted or zero.
@@ -1331,7 +1330,7 @@ The :mod:`socket` module also offers various network-related services:
13311330

13321331
Send the list of file descriptors *fds* over an :const:`AF_UNIX` socket *sock*.
13331332
The *fds* parameter is a sequence of file descriptors.
1334-
Consult :meth:`sendmsg` for the documentation of these parameters.
1333+
Consult :meth:`~socket.sendmsg` for the documentation of these parameters.
13351334

13361335
.. availability:: Unix, Windows, not Emscripten, not WASI.
13371336

@@ -1345,7 +1344,7 @@ The :mod:`socket` module also offers various network-related services:
13451344

13461345
Receive up to *maxfds* file descriptors from an :const:`AF_UNIX` socket *sock*.
13471346
Return ``(msg, list(fds), flags, addr)``.
1348-
Consult :meth:`recvmsg` for the documentation of these parameters.
1347+
Consult :meth:`~socket.recvmsg` for the documentation of these parameters.
13491348

13501349
.. availability:: Unix, Windows, not Emscripten, not WASI.
13511350

@@ -2064,10 +2063,10 @@ Example
20642063

20652064
Here are four minimal example programs using the TCP/IP protocol: a server that
20662065
echoes all data that it receives back (servicing only one client), and a client
2067-
using it. Note that a server must perform the sequence :func:`.socket`,
2066+
using it. Note that a server must perform the sequence :func:`~socket.socket`,
20682067
:meth:`~socket.bind`, :meth:`~socket.listen`, :meth:`~socket.accept` (possibly
20692068
repeating the :meth:`~socket.accept` to service more than one client), while a
2070-
client only needs the sequence :func:`.socket`, :meth:`~socket.connect`. Also
2069+
client only needs the sequence :func:`~socket.socket`, :meth:`~socket.connect`. Also
20712070
note that the server does not :meth:`~socket.sendall`/:meth:`~socket.recv` on
20722071
the socket it is listening on but on the new socket returned by
20732072
:meth:`~socket.accept`.

Doc/library/sqlite3.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ Cursor objects
15021502

15031503
.. method:: execute(sql, parameters=(), /)
15041504

1505-
Execute SQL a single SQL statement,
1505+
Execute a single SQL statement,
15061506
optionally binding Python values using
15071507
:ref:`placeholders <sqlite3-placeholders>`.
15081508

Doc/library/tkinter.ttk.rst

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,8 @@ option. If you don't know the class name of a widget, use the method
13911391
.. method:: element_create(elementname, etype, *args, **kw)
13921392

13931393
Create a new element in the current theme, of the given *etype* which is
1394-
expected to be either "image" or "from".
1394+
expected to be either "image", "from" or "vsapi".
1395+
The latter is only available in Tk 8.6 on Windows.
13951396

13961397
If "image" is used, *args* should contain the default image name followed
13971398
by statespec/value pairs (this is the imagespec), and *kw* may have the
@@ -1439,6 +1440,63 @@ option. If you don't know the class name of a widget, use the method
14391440
style = ttk.Style(root)
14401441
style.element_create('plain.background', 'from', 'default')
14411442

1443+
If "vsapi" is used as the value of *etype*, :meth:`element_create`
1444+
will create a new element in the current theme whose visual appearance
1445+
is drawn using the Microsoft Visual Styles API which is responsible
1446+
for the themed styles on Windows XP and Vista.
1447+
*args* is expected to contain the Visual Styles class and part as
1448+
given in the Microsoft documentation followed by an optional sequence
1449+
of tuples of ttk states and the corresponding Visual Styles API state
1450+
value.
1451+
*kw* may have the following options:
1452+
1453+
padding=padding
1454+
Specify the element's interior padding.
1455+
*padding* is a list of up to four integers specifying the left,
1456+
top, right and bottom padding quantities respectively.
1457+
If fewer than four elements are specified, bottom defaults to top,
1458+
right defaults to left, and top defaults to left.
1459+
In other words, a list of three numbers specify the left, vertical,
1460+
and right padding; a list of two numbers specify the horizontal
1461+
and the vertical padding; a single number specifies the same
1462+
padding all the way around the widget.
1463+
This option may not be mixed with any other options.
1464+
1465+
margins=padding
1466+
Specifies the elements exterior padding.
1467+
*padding* is a list of up to four integers specifying the left, top,
1468+
right and bottom padding quantities respectively.
1469+
This option may not be mixed with any other options.
1470+
1471+
width=width
1472+
Specifies the width for the element.
1473+
If this option is set then the Visual Styles API will not be queried
1474+
for the recommended size or the part.
1475+
If this option is set then *height* should also be set.
1476+
The *width* and *height* options cannot be mixed with the *padding*
1477+
or *margins* options.
1478+
1479+
height=height
1480+
Specifies the height of the element.
1481+
See the comments for *width*.
1482+
1483+
Example::
1484+
1485+
style = ttk.Style(root)
1486+
style.element_create('pin', 'vsapi', 'EXPLORERBAR', 3, [
1487+
('pressed', '!selected', 3),
1488+
('active', '!selected', 2),
1489+
('pressed', 'selected', 6),
1490+
('active', 'selected', 5),
1491+
('selected', 4),
1492+
('', 1)])
1493+
style.layout('Explorer.Pin',
1494+
[('Explorer.Pin.pin', {'sticky': 'news'})])
1495+
pin = ttk.Checkbutton(style='Explorer.Pin')
1496+
pin.pack(expand=True, fill='both')
1497+
1498+
.. versionchanged:: 3.13
1499+
Added support of the "vsapi" element factory.
14421500

14431501
.. method:: element_names()
14441502

Doc/whatsnew/2.0.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -671,9 +671,9 @@ errors. If you absolutely must use 2.0 but can't fix your code, you can edit
671671
``NO_STRICT_LIST_APPEND`` to preserve the old behaviour; this isn't recommended.
672672

673673
Some of the functions in the :mod:`socket` module are still forgiving in this
674-
way. For example, :func:`socket.connect( ('hostname', 25) )` is the correct
675-
form, passing a tuple representing an IP address, but :func:`socket.connect(
676-
'hostname', 25 )` also works. :func:`socket.connect_ex` and :func:`socket.bind`
674+
way. For example, ``socket.connect( ('hostname', 25) )`` is the correct
675+
form, passing a tuple representing an IP address, but ``socket.connect('hostname', 25)``
676+
also works. :meth:`socket.connect_ex <socket.socket.connect_ex>` and :meth:`socket.bind <socket.socket.bind>`
677677
are similarly easy-going. 2.0alpha1 tightened these functions up, but because
678678
the documentation actually used the erroneous multiple argument form, many
679679
people wrote code which would break with the stricter checking. GvR backed out

Doc/whatsnew/2.7.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2383,8 +2383,8 @@ Port-Specific Changes: Mac OS X
23832383
Port-Specific Changes: FreeBSD
23842384
-----------------------------------
23852385

2386-
* FreeBSD 7.1's :const:`SO_SETFIB` constant, used with
2387-
:func:`~socket.getsockopt`/:func:`~socket.setsockopt` to select an
2386+
* FreeBSD 7.1's :const:`SO_SETFIB` constant, used with the :func:`~socket.socket` methods
2387+
:func:`~socket.socket.getsockopt`/:func:`~socket.socket.setsockopt` to select an
23882388
alternate routing table, is now available in the :mod:`socket`
23892389
module. (Added by Kyle VanderBeek; :issue:`8235`.)
23902390

Doc/whatsnew/3.12.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,14 @@ Others
17731773
(*ssl_context* in :mod:`imaplib`) instead.
17741774
(Contributed by Victor Stinner in :gh:`94172`.)
17751775

1776+
* Remove ``Jython`` compatibility hacks from several stdlib modules and tests.
1777+
(Contributed by Nikita Sobolev in :gh:`99482`.)
1778+
1779+
* Remove ``_use_broken_old_ctypes_structure_semantics_`` flag
1780+
from :mod:`ctypes` module.
1781+
(Contributed by Nikita Sobolev in :gh:`99285`.)
1782+
1783+
17761784
.. _whatsnew312-porting-to-python312:
17771785

17781786
Porting to Python 3.12
@@ -2424,10 +2432,3 @@ Removed
24242432

24252433
* Remove the ``PyUnicode_InternImmortal()`` function macro.
24262434
(Contributed by Victor Stinner in :gh:`85858`.)
2427-
2428-
* Remove ``Jython`` compatibility hacks from several stdlib modules and tests.
2429-
(Contributed by Nikita Sobolev in :gh:`99482`.)
2430-
2431-
* Remove ``_use_broken_old_ctypes_structure_semantics_`` flag
2432-
from :mod:`ctypes` module.
2433-
(Contributed by Nikita Sobolev in :gh:`99285`.)

Doc/whatsnew/3.13.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ pdb
285285
identified and executed.
286286
(Contributed by Tian Gao in :gh:`108464`.)
287287

288+
* ``sys.path[0]`` will no longer be replaced by the directory of the script
289+
being debugged when ``sys.flags.safe_path`` is set (via the :option:`-P`
290+
command line option or :envvar:`PYTHONSAFEPATH` environment variable).
291+
(Contributed by Tian Gao and Christian Walther in :gh:`111762`.)
292+
288293
sqlite3
289294
-------
290295

@@ -301,6 +306,11 @@ tkinter
301306
:meth:`!tk_busy_current`, and :meth:`!tk_busy_status`.
302307
(Contributed by Miguel, klappnase and Serhiy Storchaka in :gh:`72684`.)
303308

309+
* Add support of the "vsapi" element type in
310+
the :meth:`~tkinter.ttk.Style.element_create` method of
311+
:class:`tkinter.ttk.Style`.
312+
(Contributed by Serhiy Storchaka in :gh:`68166`.)
313+
304314
traceback
305315
---------
306316

@@ -1032,6 +1042,10 @@ Changes in the Python API
10321042
recomended in the documentation.
10331043
(Contributed by Serhiy Storchaka in :gh:`106672`.)
10341044

1045+
* An :exc:`OSError` is now raised by :func:`getpass.getuser` for any failure to
1046+
retrieve a username, instead of :exc:`ImportError` on non-Unix platforms or
1047+
:exc:`KeyError` on Unix platforms where the password database is empty.
1048+
10351049

10361050
Build Changes
10371051
=============

Lib/getpass.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,24 @@ def getuser():
156156
157157
First try various environment variables, then the password
158158
database. This works on Windows as long as USERNAME is set.
159+
Any failure to find a username raises OSError.
159160
161+
.. versionchanged:: 3.13
162+
Previously, various exceptions beyond just :exc:`OSError`
163+
were raised.
160164
"""
161165

162166
for name in ('LOGNAME', 'USER', 'LNAME', 'USERNAME'):
163167
user = os.environ.get(name)
164168
if user:
165169
return user
166170

167-
# If this fails, the exception will "explain" why
168-
import pwd
169-
return pwd.getpwuid(os.getuid())[0]
171+
try:
172+
import pwd
173+
return pwd.getpwuid(os.getuid())[0]
174+
except (ImportError, KeyError) as e:
175+
raise OSError('No username set in the environment') from e
176+
170177

171178
# Bind the name getpass to the appropriate function
172179
try:

Lib/importlib/_bootstrap.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,10 +824,16 @@ def _module_repr_from_spec(spec):
824824
"""Return the repr to use for the module."""
825825
name = '?' if spec.name is None else spec.name
826826
if spec.origin is None:
827-
if spec.loader is None:
827+
loader = spec.loader
828+
if loader is None:
828829
return f'<module {name!r}>'
830+
elif (
831+
_bootstrap_external is not None
832+
and isinstance(loader, _bootstrap_external.NamespaceLoader)
833+
):
834+
return f'<module {name!r} (namespace) from {list(loader._path)}>'
829835
else:
830-
return f'<module {name!r} (namespace) from {list(spec.loader._path)}>'
836+
return f'<module {name!r} ({loader!r})>'
831837
else:
832838
if spec.has_location:
833839
return f'<module {name!r} from {spec.origin!r}>'

Lib/pdb.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ def check(self):
142142
print('Error:', self.orig, 'is a directory')
143143
sys.exit(1)
144144

145-
# Replace pdb's dir with script's dir in front of module search path.
146-
sys.path[0] = os.path.dirname(self)
145+
# If safe_path(-P) is not set, sys.path[0] is the directory
146+
# of pdb, and we should replace it with the directory of the script
147+
if not sys.flags.safe_path:
148+
sys.path[0] = os.path.dirname(self)
147149

148150
@property
149151
def filename(self):

Lib/ssl.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,10 +1270,14 @@ def recv(self, buflen=1024, flags=0):
12701270

12711271
def recv_into(self, buffer, nbytes=None, flags=0):
12721272
self._checkClosed()
1273-
if buffer and (nbytes is None):
1274-
nbytes = len(buffer)
1275-
elif nbytes is None:
1276-
nbytes = 1024
1273+
if nbytes is None:
1274+
if buffer is not None:
1275+
with memoryview(buffer) as view:
1276+
nbytes = view.nbytes
1277+
if not nbytes:
1278+
nbytes = 1024
1279+
else:
1280+
nbytes = 1024
12771281
if self._sslobj is not None:
12781282
if flags != 0:
12791283
raise ValueError(

0 commit comments

Comments
 (0)