Skip to content

Commit 12cae51

Browse files
authored
Merge branch 'main' into multi_inputs
2 parents 09b97d9 + 02de9cb commit 12cae51

71 files changed

Lines changed: 1133 additions & 420 deletions

File tree

Some content is hidden

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

Doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101
# Minimum version of sphinx required
102102
# Keep this version in sync with ``Doc/requirements.txt``.
103-
needs_sphinx = '8.1.3'
103+
needs_sphinx = '8.2.0'
104104

105105
# Create table of contents entries for domain objects (e.g. functions, classes,
106106
# attributes, etc.). Default is True.

Doc/deprecations/pending-removal-in-future.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ although there is currently no date scheduled for their removal.
127127

128128
* :class:`typing.Text` (:gh:`92332`).
129129

130+
* The internal class ``typing._UnionGenericAlias`` is no longer used to implement
131+
:class:`typing.Union`. To preserve compatibility with users using this private
132+
class, a compatibility shim will be provided until at least Python 3.17. (Contributed by
133+
Jelle Zijlstra in :gh:`105499`.)
134+
130135
* :class:`unittest.IsolatedAsyncioTestCase`: it is deprecated to return a value
131136
that is not ``None`` from a test case.
132137

Doc/library/functools.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ The :mod:`functools` module defines the following functions:
518518
... for i, elem in enumerate(arg):
519519
... print(i, elem)
520520

521-
:data:`types.UnionType` and :data:`typing.Union` can also be used::
521+
:class:`typing.Union` can also be used::
522522

523523
>>> @fun.register
524524
... def _(arg: int | float, verbose=False):
@@ -654,8 +654,8 @@ The :mod:`functools` module defines the following functions:
654654
The :func:`register` attribute now supports using type annotations.
655655

656656
.. versionchanged:: 3.11
657-
The :func:`register` attribute now supports :data:`types.UnionType`
658-
and :data:`typing.Union` as type annotations.
657+
The :func:`register` attribute now supports
658+
:class:`typing.Union` as a type annotation.
659659

660660

661661
.. class:: singledispatchmethod(func)

Doc/library/stdtypes.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5364,7 +5364,7 @@ Union Type
53645364
A union object holds the value of the ``|`` (bitwise or) operation on
53655365
multiple :ref:`type objects <bltin-type-objects>`. These types are intended
53665366
primarily for :term:`type annotations <annotation>`. The union type expression
5367-
enables cleaner type hinting syntax compared to :data:`typing.Union`.
5367+
enables cleaner type hinting syntax compared to subscripting :class:`typing.Union`.
53685368

53695369
.. describe:: X | Y | ...
53705370

@@ -5400,9 +5400,10 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
54005400

54015401
int | str == str | int
54025402

5403-
* It is compatible with :data:`typing.Union`::
5403+
* It creates instances of :class:`typing.Union`::
54045404

54055405
int | str == typing.Union[int, str]
5406+
type(int | str) is typing.Union
54065407

54075408
* Optional types can be spelled as a union with ``None``::
54085409

@@ -5428,16 +5429,15 @@ enables cleaner type hinting syntax compared to :data:`typing.Union`.
54285429
TypeError: isinstance() argument 2 cannot be a parameterized generic
54295430

54305431
The user-exposed type for the union object can be accessed from
5431-
:data:`types.UnionType` and used for :func:`isinstance` checks. An object cannot be
5432-
instantiated from the type::
5432+
:class:`typing.Union` and used for :func:`isinstance` checks::
54335433

5434-
>>> import types
5435-
>>> isinstance(int | str, types.UnionType)
5434+
>>> import typing
5435+
>>> isinstance(int | str, typing.Union)
54365436
True
5437-
>>> types.UnionType()
5437+
>>> typing.Union()
54385438
Traceback (most recent call last):
54395439
File "<stdin>", line 1, in <module>
5440-
TypeError: cannot create 'types.UnionType' instances
5440+
TypeError: cannot create 'typing.Union' instances
54415441

54425442
.. note::
54435443
The :meth:`!__or__` method for type objects was added to support the syntax
@@ -5464,6 +5464,11 @@ instantiated from the type::
54645464

54655465
.. versionadded:: 3.10
54665466

5467+
.. versionchanged:: 3.14
5468+
5469+
Union objects are now instances of :class:`typing.Union`. Previously, they were instances
5470+
of :class:`types.UnionType`, which remains an alias for :class:`typing.Union`.
5471+
54675472

54685473
.. _typesother:
54695474

Doc/library/types.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ Standard names are defined for the following types:
314314

315315
.. versionadded:: 3.10
316316

317+
.. versionchanged:: 3.14
318+
319+
This is now an alias for :class:`typing.Union`.
320+
317321
.. class:: TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
318322

319323
The type of traceback objects such as found in ``sys.exception().__traceback__``.

Doc/library/typing.rst

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ provides backports of these new features to older versions of Python.
5353
should broadly apply to most Python type checkers. (Some parts may still
5454
be specific to mypy.)
5555

56-
`"Static Typing with Python" <https://typing.readthedocs.io/en/latest/>`_
56+
`"Static Typing with Python" <https://typing.python.org/en/latest/>`_
5757
Type-checker-agnostic documentation written by the community detailing
5858
type system features, useful typing related tools and typing best
5959
practices.
@@ -64,7 +64,7 @@ Specification for the Python Type System
6464
========================================
6565

6666
The canonical, up-to-date specification of the Python type system can be
67-
found at `"Specification for the Python type system" <https://typing.readthedocs.io/en/latest/spec/index.html>`_.
67+
found at `"Specification for the Python type system" <https://typing.python.org/en/latest/spec/index.html>`_.
6868

6969
.. _type-aliases:
7070

@@ -1086,7 +1086,7 @@ Special forms
10861086
These can be used as types in annotations. They all support subscription using
10871087
``[]``, but each has a unique syntax.
10881088

1089-
.. data:: Union
1089+
.. class:: Union
10901090

10911091
Union type; ``Union[X, Y]`` is equivalent to ``X | Y`` and means either X or Y.
10921092

@@ -1121,6 +1121,14 @@ These can be used as types in annotations. They all support subscription using
11211121
Unions can now be written as ``X | Y``. See
11221122
:ref:`union type expressions<types-union>`.
11231123

1124+
.. versionchanged:: 3.14
1125+
:class:`types.UnionType` is now an alias for :class:`Union`, and both
1126+
``Union[int, str]`` and ``int | str`` create instances of the same class.
1127+
To check whether an object is a ``Union`` at runtime, use
1128+
``isinstance(obj, Union)``. For compatibility with earlier versions of
1129+
Python, use
1130+
``get_origin(obj) is typing.Union or get_origin(obj) is types.UnionType``.
1131+
11241132
.. data:: Optional
11251133

11261134
``Optional[X]`` is equivalent to ``X | None`` (or ``Union[X, None]``).
@@ -2292,6 +2300,20 @@ without the dedicated syntax, as documented below.
22922300

22932301
.. versionadded:: 3.14
22942302

2303+
.. rubric:: Unpacking
2304+
2305+
Type aliases support star unpacking using the ``*Alias`` syntax.
2306+
This is equivalent to using ``Unpack[Alias]`` directly:
2307+
2308+
.. doctest::
2309+
2310+
>>> type Alias = tuple[int, str]
2311+
>>> type Unpacked = tuple[bool, *Alias]
2312+
>>> Unpacked.__value__
2313+
tuple[bool, typing.Unpack[Alias]]
2314+
2315+
.. versionadded:: next
2316+
22952317

22962318
Other special directives
22972319
""""""""""""""""""""""""
@@ -2890,7 +2912,7 @@ Functions and decorators
28902912

28912913
.. seealso::
28922914
`Unreachable Code and Exhaustiveness Checking
2893-
<https://typing.readthedocs.io/en/latest/guides/unreachable.html>`__ has more
2915+
<https://typing.python.org/en/latest/guides/unreachable.html>`__ has more
28942916
information about exhaustiveness checking with static typing.
28952917

28962918
.. versionadded:: 3.11

Doc/whatsnew/3.10.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,10 +722,10 @@ PEP 604: New Type Union Operator
722722
723723
A new type union operator was introduced which enables the syntax ``X | Y``.
724724
This provides a cleaner way of expressing 'either type X or type Y' instead of
725-
using :data:`typing.Union`, especially in type hints.
725+
using :class:`typing.Union`, especially in type hints.
726726
727727
In previous versions of Python, to apply a type hint for functions accepting
728-
arguments of multiple types, :data:`typing.Union` was used::
728+
arguments of multiple types, :class:`typing.Union` was used::
729729
730730
def square(number: Union[int, float]) -> Union[int, float]:
731731
return number ** 2

Doc/whatsnew/3.11.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ fractions
740740
functools
741741
---------
742742

743-
* :func:`functools.singledispatch` now supports :data:`types.UnionType`
744-
and :data:`typing.Union` as annotations to the dispatch argument.::
743+
* :func:`functools.singledispatch` now supports :class:`types.UnionType`
744+
and :class:`typing.Union` as annotations to the dispatch argument.::
745745

746746
>>> from functools import singledispatch
747747
>>> @singledispatch

Doc/whatsnew/3.14.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,10 @@ pdb
785785
(if any).
786786
(Contributed by Tian Gao in :gh:`130493`.)
787787

788+
* ``<tab>`` at the beginning of the line in :mod:`pdb` multi-line input will
789+
fill in a 4-space indentation now, instead of inserting a ``\t`` character.
790+
(Contributed by Tian Gao in :gh:`130471`.)
791+
788792

789793
pickle
790794
------
@@ -1326,6 +1330,8 @@ typing
13261330
* Remove :class:`!typing.ByteString`. It had previously raised a
13271331
:exc:`DeprecationWarning` since Python 3.12.
13281332

1333+
* :class:`typing.TypeAliasType` now supports star unpacking.
1334+
13291335
urllib
13301336
------
13311337

Include/internal/pycore_interp.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ struct _is {
296296

297297
#if !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
298298
uint64_t next_stackref;
299-
_Py_hashtable_t *stackref_debug_table;
299+
_Py_hashtable_t *open_stackrefs_table;
300+
# ifdef Py_STACKREF_CLOSE_DEBUG
301+
_Py_hashtable_t *closed_stackrefs_table;
302+
# endif
300303
#endif
301304
};
302305

0 commit comments

Comments
 (0)