Skip to content

Commit 79b305a

Browse files
authored
Merge branch 'main' into bpo-2920
2 parents 08b39a4 + 398d7e1 commit 79b305a

33 files changed

Lines changed: 492 additions & 83 deletions

Doc/deprecations/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Deprecations
1313

1414
.. include:: pending-removal-in-3.20.rst
1515

16+
.. include:: pending-removal-in-3.21.rst
17+
1618
.. include:: pending-removal-in-future.rst
1719

1820
.. include:: soft-deprecations.rst
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Pending removal in Python 3.21
2+
------------------------------
3+
4+
* :mod:`ast`:
5+
6+
* Classes ``slice``, ``Index``, ``ExtSlice``, ``Suite``, ``Param``,
7+
``AugLoad`` and ``AugStore``, will be removed in Python 3.21. These types
8+
are not generated by the parser or accepted by the code generator.
9+
* The ``dims`` property of ``ast.Tuple`` will be removed in Python 3.21. Use
10+
the ``ast.Tuple.elts`` property instead.

Doc/library/dataclasses.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ Module contents
418418
:func:`!astuple` raises :exc:`TypeError` if *obj* is not a dataclass
419419
instance.
420420

421-
.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False, module=None, decorator=dataclass)
421+
.. function:: make_dataclass(cls_name, fields, *, bases=(), namespace=None, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False, module=None, qualname=None, decorator=dataclass)
422422

423423
Creates a new dataclass with name *cls_name*, fields as defined
424424
in *fields*, base classes as given in *bases*, and initialized
@@ -434,6 +434,9 @@ Module contents
434434
of the dataclass is set to that value.
435435
By default, it is set to the module name of the caller.
436436

437+
If *qualname* is defined, the :attr:`~type.__qualname__` attribute of the dataclass
438+
is set to that value. By default, it is set to the value passed to *cls_name*.
439+
437440
The *decorator* parameter is a callable that will be used to create the dataclass.
438441
It should take the class object as a first argument and the same keyword arguments
439442
as :deco:`dataclass`. By default, the :deco:`dataclass`
@@ -464,6 +467,8 @@ Module contents
464467

465468
.. versionadded:: 3.14
466469
Added the *decorator* parameter.
470+
.. versionadded:: next
471+
Added the *qualname* parameter.
467472

468473
.. function:: replace(obj, /, **changes)
469474

Doc/library/inspect.rst

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,24 +424,63 @@ attributes (see :ref:`import-mod-attrs` for module attributes):
424424

425425
Return ``True`` if the object is a bound method written in Python.
426426

427+
.. note::
427428

428-
.. function:: ispackage(object)
429+
For example, given this class::
429430

430-
Return ``True`` if the object is a :term:`package`.
431+
>>> class Greeter:
432+
... def say_hello(self):
433+
... print('hello!')
431434

432-
.. versionadded:: 3.14
435+
A bound method (also known as an *instance method*) is created when
436+
accessing ``say_hello`` (a :term:`function` defined in the
437+
``Greeter`` namespace) through an instance of the ``Greeter`` class::
438+
439+
>>> instance = Greeter()
440+
441+
>>> instance.say_hello
442+
<bound method Greeter.say_hello of <__main__.Greeter object ...>>
443+
>>> ismethod(instance.say_hello)
444+
True
445+
>>> isfunction(instance.say_hello)
446+
False
447+
448+
Accessing ``say_hello`` through the ``Greeter`` class will return the
449+
function itself. For this function, :func:`ismethod` will return
450+
``False``, but :func:`isfunction` will return ``True``::
451+
452+
>>> Greeter.say_hello
453+
<function Greeter.say_hello at 0x7f7503854a90>
454+
>>> ismethod(Greeter.say_hello)
455+
False
456+
>>> isfunction(Greeter.say_hello)
457+
True
458+
459+
See :ref:`typesmethods` for details.
433460

434461

435462
.. function:: isfunction(object)
436463

437464
Return ``True`` if the object is a Python function, which includes functions
438465
created by a :term:`lambda` expression.
439466

467+
See the note for :func:`~inspect.ismethod` for an example.
468+
469+
470+
.. function:: ispackage(object)
471+
472+
Return ``True`` if the object is a :term:`package`.
473+
474+
.. versionadded:: 3.14
475+
440476

441477
.. function:: isgeneratorfunction(object)
442478

443479
Return ``True`` if the object is a Python generator function.
444480

481+
It also returns ``True`` for bound methods created from Python generator functions
482+
(see :ref:`typesmethods` for more information).
483+
445484
.. versionchanged:: 3.8
446485
Functions wrapped in :func:`functools.partial` now return ``True`` if the
447486
wrapped function is a Python generator function.

Doc/library/os.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2549,7 +2549,8 @@ features:
25492549
Windows now handles a *mode* of ``0o700``.
25502550

25512551

2552-
.. function:: makedirs(name, mode=0o777, exist_ok=False)
2552+
.. function:: makedirs(name, mode=0o777, exist_ok=False, *, \
2553+
parent_mode=None)
25532554

25542555
.. index::
25552556
single: directory; creating
@@ -2567,6 +2568,12 @@ features:
25672568
If *exist_ok* is ``False`` (the default), a :exc:`FileExistsError` is
25682569
raised if the target directory already exists.
25692570

2571+
If *parent_mode* is not ``None``, it is used as the mode for any
2572+
newly-created, intermediate-level directories. Like *mode*, it is
2573+
combined with the process's umask value; see :ref:`the mkdir()
2574+
description <mkdir_modebits>`. Otherwise, intermediate directories are
2575+
created with the default mode, which is also subject to the umask.
2576+
25702577
.. note::
25712578

25722579
:func:`makedirs` will become confused if the path elements to create
@@ -2593,6 +2600,11 @@ features:
25932600
The *mode* argument no longer affects the file permission bits of
25942601
newly created intermediate-level directories.
25952602

2603+
.. versionadded:: 3.15
2604+
The *parent_mode* parameter. To match the behavior from Python 3.6 and
2605+
earlier (where *mode* was applied to all created directories), pass
2606+
``parent_mode=mode``.
2607+
25962608

25972609
.. function:: mkfifo(path, mode=0o666, *, dir_fd=None)
25982610

Doc/library/pathlib.rst

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,8 @@ Creating files and directories
15181518
:meth:`~Path.write_bytes` methods are often used to create files.
15191519

15201520

1521-
.. method:: Path.mkdir(mode=0o777, parents=False, exist_ok=False)
1521+
.. method:: Path.mkdir(mode=0o777, parents=False, exist_ok=False, *, \
1522+
parent_mode=None)
15221523

15231524
Create a new directory at this given path. If *mode* is given, it is
15241525
combined with the process's ``umask`` value to determine the file mode
@@ -1529,6 +1530,12 @@ Creating files and directories
15291530
as needed; they are created with the default permissions without taking
15301531
*mode* into account (mimicking the POSIX ``mkdir -p`` command).
15311532

1533+
If *parent_mode* is not ``None``, it is used as the mode for any
1534+
newly-created, intermediate-level directories when *parents* is true.
1535+
Like *mode*, it is combined with the process's ``umask`` value.
1536+
Otherwise, intermediate directories are created with the default
1537+
permissions (also subject to the umask).
1538+
15321539
If *parents* is false (the default), a missing parent raises
15331540
:exc:`FileNotFoundError`.
15341541

@@ -1542,6 +1549,9 @@ Creating files and directories
15421549
.. versionchanged:: 3.5
15431550
The *exist_ok* parameter was added.
15441551

1552+
.. versionadded:: 3.15
1553+
The *parent_mode* parameter.
1554+
15451555

15461556
.. method:: Path.symlink_to(target, target_is_directory=False)
15471557

Doc/library/ssl.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2076,7 +2076,7 @@ to speed up repeated connections from the same clients.
20762076
:attr:`~SSLContext.minimum_version` and
20772077
:attr:`SSLContext.options` all affect the supported SSL
20782078
and TLS versions of the context. The implementation does not prevent
2079-
invalid combination. For example a context with
2079+
invalid combinations. For example a context with
20802080
:attr:`OP_NO_TLSv1_2` in :attr:`~SSLContext.options` and
20812081
:attr:`~SSLContext.maximum_version` set to :attr:`TLSVersion.TLSv1_2`
20822082
will not be able to establish a TLS 1.2 connection.
@@ -2891,11 +2891,11 @@ disabled by default.
28912891
::
28922892

28932893
>>> client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
2894-
>>> client_context.minimum_version = ssl.TLSVersion.TLSv1_3
2894+
>>> client_context.minimum_version = ssl.TLSVersion.TLSv1_2
28952895
>>> client_context.maximum_version = ssl.TLSVersion.TLSv1_3
28962896

28972897

2898-
The SSL context created above will only allow TLSv1.3 and later (if
2898+
The SSL client context created above will only allow TLSv1.2 and TLSv1.3 (if
28992899
supported by your system) connections to a server. :const:`PROTOCOL_TLS_CLIENT`
29002900
implies certificate validation and hostname checks by default. You have to
29012901
load certificates into the context.

Doc/whatsnew/3.15.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,10 @@ os
12851285
glibc versions 2.28 and later.
12861286
(Contributed by Jeffrey Bosboom and Victor Stinner in :gh:`83714`.)
12871287

1288+
* :func:`os.makedirs` function now has a *parent_mode* parameter that allows
1289+
specifying the mode for intermediate directories. This can be used to match
1290+
the behavior from Python 3.6 and earlier by passing ``parent_mode=mode``.
1291+
(Contributed by Zackery Spytz and Gregory P. Smith in :gh:`86533`.)
12881292

12891293
os.path
12901294
-------
@@ -2057,6 +2061,10 @@ importlib.resources
20572061
pathlib
20582062
-------
20592063

2064+
* :meth:`pathlib.Path.mkdir` now has a *parent_mode* parameter that allows
2065+
specifying the mode for intermediate directories when ``parents=True``.
2066+
(Contributed by Gregory P. Smith in :gh:`86533`.)
2067+
20602068
* Removed deprecated :meth:`!pathlib.PurePath.is_reserved`.
20612069
Use :func:`os.path.isreserved` to detect reserved paths on Windows.
20622070
(Contributed by Nikita Sobolev in :gh:`133875`.)

Doc/whatsnew/3.16.rst

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,16 @@ tarfile
184184
Deprecated
185185
==========
186186

187-
* module_name:
188-
TODO
189-
187+
* :mod:`ast`:
188+
189+
* Classes ``slice``, ``Index``, ``ExtSlice``, ``Suite``, ``Param``,
190+
``AugLoad`` and ``AugStore``, deprecated since Python 3.9, are no longer
191+
imported by ``from ast import *`` and issue a deprecation warning on
192+
use. The classes are slated for removal in Python 3.21. These types are not
193+
generated by the parser or accepted by the code generator.
194+
* The ``dims`` property of ``ast.Tuple`` objects, deprecated since Python
195+
3.9, now issues a deprecation warning on use. This property is slated for
196+
removal in 3.21. Use ``ast.Tuple.elts`` instead.
190197

191198
.. Add deprecations above alphabetically, not here at the end.
192199

Lib/ast.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
:license: Python License.
2222
"""
2323
from _ast import *
24-
24+
lazy import warnings
2525

2626
def parse(source, filename='<unknown>', mode='exec', *,
2727
type_comments=False, feature_version=None, optimize=-1, module=None):
@@ -630,9 +630,11 @@ def __new__(cls, dims=(), **kwargs):
630630

631631
def _dims_getter(self):
632632
"""Deprecated. Use elts instead."""
633+
warnings._deprecated(f"ast.Tuple.dims", remove=(3, 21))
633634
return self.elts
634635

635636
def _dims_setter(self, value):
637+
warnings._deprecated(f"ast.Tuple.dims", remove=(3, 21))
636638
self.elts = value
637639

638640
Tuple.dims = property(_dims_getter, _dims_setter)
@@ -714,5 +716,23 @@ def main(args=None):
714716
color=can_colorize(file=sys.stdout),
715717
indent=args.indent, show_empty=args.show_empty))
716718

719+
_deprecated = {
720+
'slice': globals().pop("slice"),
721+
'Index': globals().pop("Index"),
722+
'ExtSlice': globals().pop("ExtSlice"),
723+
'Suite': globals().pop("Suite"),
724+
'AugLoad': globals().pop("AugLoad"),
725+
'AugStore': globals().pop("AugStore"),
726+
'Param': globals().pop("Param")
727+
}
728+
729+
def __getattr__(attr):
730+
try:
731+
val = _deprecated[attr]
732+
except KeyError:
733+
raise AttributeError(f"module 'ast' has no attribute {attr!r}") from None
734+
warnings._deprecated(f"ast.{attr}", remove=(3, 21))
735+
return val
736+
717737
if __name__ == '__main__':
718738
main()

0 commit comments

Comments
 (0)