Skip to content

Commit fbd02f3

Browse files
authored
Merge branch 'main' into ast-deprecation-warnings
2 parents b2ca297 + 97e7004 commit fbd02f3

File tree

188 files changed

+2368
-1036
lines changed

Some content is hidden

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

188 files changed

+2368
-1036
lines changed

Doc/_static/og-image.png

14.2 KB
Loading

Doc/conf.py

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,25 @@
1313
# General configuration
1414
# ---------------------
1515

16-
extensions = ['sphinx.ext.coverage', 'sphinx.ext.doctest',
17-
'pyspecific', 'c_annotations', 'escape4chm',
18-
'asdl_highlight', 'peg_highlight', 'glossary_search']
16+
extensions = [
17+
'asdl_highlight',
18+
'c_annotations',
19+
'escape4chm',
20+
'glossary_search',
21+
'peg_highlight',
22+
'pyspecific',
23+
'sphinx.ext.coverage',
24+
'sphinx.ext.doctest',
25+
]
26+
27+
# Skip if downstream redistributors haven't installed it
28+
try:
29+
import sphinxext.opengraph
30+
except ImportError:
31+
pass
32+
else:
33+
extensions.append('sphinxext.opengraph')
34+
1935

2036
doctest_global_setup = '''
2137
try:
@@ -89,6 +105,14 @@
89105
# Short title used e.g. for <title> HTML tags.
90106
html_short_title = '%s Documentation' % release
91107

108+
# Deployment preview information, from Netlify
109+
# (See netlify.toml and https://docs.netlify.com/configure-builds/environment-variables/#git-metadata)
110+
html_context = {
111+
"is_deployment_preview": os.getenv("IS_DEPLOYMENT_PREVIEW"),
112+
"repository_url": os.getenv("REPOSITORY_URL"),
113+
"pr_id": os.getenv("REVIEW_ID")
114+
}
115+
92116
# If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
93117
# using the given strftime format.
94118
html_last_updated_fmt = '%b %d, %Y'
@@ -114,7 +138,7 @@
114138
html_use_opensearch = 'https://docs.python.org/' + version
115139

116140
# Additional static files.
117-
html_static_path = ['tools/static']
141+
html_static_path = ['_static', 'tools/static']
118142

119143
# Output file base name for HTML help builder.
120144
htmlhelp_basename = 'python' + release.replace('.', '')
@@ -238,3 +262,13 @@
238262
# Relative filename of the data files
239263
refcount_file = 'data/refcounts.dat'
240264
stable_abi_file = 'data/stable_abi.dat'
265+
266+
# sphinxext-opengraph config
267+
ogp_site_url = 'https://docs.python.org/3/'
268+
ogp_site_name = 'Python documentation'
269+
ogp_image = '_static/og-image.png'
270+
ogp_custom_meta_tags = [
271+
'<meta property="og:image:width" content="200">',
272+
'<meta property="og:image:height" content="200">',
273+
'<meta name="theme-color" content="#3776ab">',
274+
]

Doc/howto/enum.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,31 @@ sense to allow sharing some common behavior between a group of enumerations.
459459
(See `OrderedEnum`_ for an example.)
460460

461461

462+
.. _enum-dataclass-support:
463+
464+
Dataclass support
465+
-----------------
466+
467+
When inheriting from a :class:`~dataclasses.dataclass`,
468+
the :meth:`~Enum.__repr__` omits the inherited class' name. For example::
469+
470+
>>> @dataclass
471+
... class CreatureDataMixin:
472+
... size: str
473+
... legs: int
474+
... tail: bool = field(repr=False, default=True)
475+
...
476+
>>> class Creature(CreatureDataMixin, Enum):
477+
... BEETLE = 'small', 6
478+
... DOG = 'medium', 4
479+
...
480+
>>> Creature.DOG
481+
<Creature.DOG: size='medium', legs=4>
482+
483+
Use the :func:`!dataclass` argument ``repr=False``
484+
to use the standard :func:`repr`.
485+
486+
462487
Pickling
463488
--------
464489

Doc/library/asyncio-eventloop.rst

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ an event loop:
3333

3434
Return the running event loop in the current OS thread.
3535

36-
If there is no running event loop a :exc:`RuntimeError` is raised.
36+
Raise a :exc:`RuntimeError` if there is no running event loop.
37+
3738
This function can only be called from a coroutine or a callback.
3839

3940
.. versionadded:: 3.7
@@ -42,27 +43,31 @@ an event loop:
4243

4344
Get the current event loop.
4445

45-
If there is no current event loop set in the current OS thread,
46-
the OS thread is main, and :func:`set_event_loop` has not yet
47-
been called, asyncio will create a new event loop and set it as the
48-
current one.
46+
When called from a coroutine or a callback (e.g. scheduled with
47+
call_soon or similar API), this function will always return the
48+
running event loop.
49+
50+
If there is no running event loop set, the function will return
51+
the result of calling ``get_event_loop_policy().get_event_loop()``.
4952

5053
Because this function has rather complex behavior (especially
5154
when custom event loop policies are in use), using the
5255
:func:`get_running_loop` function is preferred to :func:`get_event_loop`
5356
in coroutines and callbacks.
5457

55-
Consider also using the :func:`asyncio.run` function instead of using
56-
lower level functions to manually create and close an event loop.
58+
As noted above, consider using the higher-level :func:`asyncio.run` function,
59+
instead of using these lower level functions to manually create and close an
60+
event loop.
5761

58-
.. deprecated:: 3.10
59-
Deprecation warning is emitted if there is no running event loop.
60-
In future Python releases, this function will be an alias of
61-
:func:`get_running_loop`.
62+
.. note::
63+
In Python versions 3.10.0--3.10.8 and 3.11.0 this function
64+
(and other functions which used it implicitly) emitted a
65+
:exc:`DeprecationWarning` if there was no running event loop, even if
66+
the current loop was set.
6267

6368
.. function:: set_event_loop(loop)
6469

65-
Set *loop* as a current event loop for the current OS thread.
70+
Set *loop* as the current event loop for the current OS thread.
6671

6772
.. function:: new_event_loop()
6873

Doc/library/asyncio-llapi-index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Obtaining the Event Loop
1919
- The **preferred** function to get the running event loop.
2020

2121
* - :func:`asyncio.get_event_loop`
22-
- Get an event loop instance (current or via the policy).
22+
- Get an event loop instance (running or current via the current policy).
2323

2424
* - :func:`asyncio.set_event_loop`
2525
- Set the event loop as current via the current policy.

Doc/library/asyncio-policy.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ asyncio ships with the following built-in policies:
116116

117117
On Windows, :class:`ProactorEventLoop` is now used by default.
118118

119+
.. versionchanged:: 3.12
120+
:meth:`get_event_loop` now raises a :exc:`RuntimeError` if there is no
121+
current event loop set.
122+
119123

120124
.. class:: WindowsSelectorEventLoopPolicy
121125

Doc/library/dataclasses.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ Module contents
7979
class C:
8080
...
8181

82-
@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False, match_args=True, kw_only=False, slots=False, weakref_slot=False)
82+
@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False,
83+
match_args=True, kw_only=False, slots=False, weakref_slot=False)
8384
class C:
8485
...
8586

Doc/library/enum.rst

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Data Types
194194

195195
.. method:: EnumType.__getitem__(cls, name)
196196

197-
Returns the Enum member in *cls* matching *name*, or raises an :exc:`KeyError`::
197+
Returns the Enum member in *cls* matching *name*, or raises a :exc:`KeyError`::
198198

199199
>>> Color['BLUE']
200200
<Color.BLUE: 3>
@@ -241,7 +241,7 @@ Data Types
241241

242242
.. note:: Enum member values
243243

244-
Member values can be anything: :class:`int`, :class:`str`, etc.. If
244+
Member values can be anything: :class:`int`, :class:`str`, etc. If
245245
the exact value is unimportant you may use :class:`auto` instances and an
246246
appropriate value will be chosen for you. See :class:`auto` for the
247247
details.
@@ -255,7 +255,7 @@ Data Types
255255
names will also be removed from the completed enumeration. See
256256
:ref:`TimePeriod <enum-time-period>` for an example.
257257

258-
.. method:: Enum.__call__(cls, value, names=None, \*, module=None, qualname=None, type=None, start=1, boundary=None)
258+
.. method:: Enum.__call__(cls, value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)
259259

260260
This method is called in two different ways:
261261

@@ -272,8 +272,8 @@ Data Types
272272
:module: The name of the module the new Enum is created in.
273273
:qualname: The actual location in the module where this Enum can be found.
274274
:type: A mix-in type for the new Enum.
275-
:start: The first integer value for the Enum (used by :class:`auto`)
276-
:boundary: How to handle out-of-range values from bit operations (:class:`Flag` only)
275+
:start: The first integer value for the Enum (used by :class:`auto`).
276+
:boundary: How to handle out-of-range values from bit operations (:class:`Flag` only).
277277

278278
.. method:: Enum.__dir__(self)
279279

@@ -315,7 +315,7 @@ Data Types
315315
>>> PowersOfThree.SECOND.value
316316
6
317317

318-
.. method:: Enum.__init_subclass__(cls, \**kwds)
318+
.. method:: Enum.__init_subclass__(cls, **kwds)
319319

320320
A *classmethod* that is used to further configure subsequent subclasses.
321321
By default, does nothing.
@@ -373,7 +373,7 @@ Data Types
373373
.. method:: Enum.__format__(self)
374374

375375
Returns the string used for *format()* and *f-string* calls. By default,
376-
returns :meth:`__str__` returns, but can be overridden::
376+
returns :meth:`__str__` return value, but can be overridden::
377377

378378
>>> class OtherStyle(Enum):
379379
... ALTERNATE = auto()
@@ -389,6 +389,8 @@ Data Types
389389
Using :class:`auto` with :class:`Enum` results in integers of increasing value,
390390
starting with ``1``.
391391

392+
.. versionchanged:: 3.12 Added :ref:`enum-dataclass-support`
393+
392394

393395
.. class:: IntEnum
394396

@@ -552,11 +554,11 @@ Data Types
552554
Using :class:`auto` with :class:`Flag` results in integers that are powers
553555
of two, starting with ``1``.
554556

555-
.. versionchanged:: 3.11 The *repr()* of zero-valued flags has changed. It
557+
.. versionchanged:: 3.11 The *repr()* of zero-valued flags has changed. It
556558
is now::
557559

558-
>>> Color(0) # doctest: +SKIP
559-
<Color: 0>
560+
>>> Color(0) # doctest: +SKIP
561+
<Color: 0>
560562

561563
.. class:: IntFlag
562564

@@ -600,7 +602,7 @@ Data Types
600602
*replacement of existing constants* use-case. :meth:`~object.__format__` was
601603
already :meth:`!int.__format__` for that same reason.
602604

603-
Inversion of a :class:`!IntFlag` now returns a positive value that is the
605+
Inversion of an :class:`!IntFlag` now returns a positive value that is the
604606
union of all flags not in the given flag, rather than a negative value.
605607
This matches the existing :class:`Flag` behavior.
606608

@@ -612,7 +614,7 @@ Data Types
612614
* :meth:`!int.__str__` for :class:`IntEnum` and :class:`IntFlag`
613615
* :meth:`!str.__str__` for :class:`StrEnum`
614616

615-
Inherit from :class:`!ReprEnum` to keep the :class:`str() <str> / :func:`format`
617+
Inherit from :class:`!ReprEnum` to keep the :class:`str() <str>` / :func:`format`
616618
of the mixed-in data type instead of using the
617619
:class:`Enum`-default :meth:`str() <Enum.__str__>`.
618620

@@ -658,7 +660,7 @@ Data Types
658660
.. attribute:: NAMED_FLAGS
659661

660662
Ensure that any flag groups/masks contain only named flags -- useful when
661-
values are specified instead of being generated by :func:`auto`
663+
values are specified instead of being generated by :func:`auto`::
662664

663665
>>> from enum import Flag, verify, NAMED_FLAGS
664666
>>> @verify(NAMED_FLAGS)
@@ -804,6 +806,11 @@ Utilities and Decorators
804806
* ``THREE = [auto(), -3]`` will *not* work (``<auto instance>, -3`` is used to
805807
create the ``THREE`` enum member)
806808

809+
.. versionchanged:: 3.11.1
810+
811+
In prior versions, ``auto()`` had to be the only thing
812+
on the assignment line to work properly.
813+
807814
``_generate_next_value_`` can be overridden to customize the values used by
808815
*auto*.
809816

@@ -885,23 +892,23 @@ Notes
885892

886893
:class:`IntEnum`, :class:`StrEnum`, and :class:`IntFlag`
887894

888-
These three enum types are designed to be drop-in replacements for existing
889-
integer- and string-based values; as such, they have extra limitations:
895+
These three enum types are designed to be drop-in replacements for existing
896+
integer- and string-based values; as such, they have extra limitations:
890897

891-
- ``__str__`` uses the value and not the name of the enum member
898+
- ``__str__`` uses the value and not the name of the enum member
892899

893-
- ``__format__``, because it uses ``__str__``, will also use the value of
894-
the enum member instead of its name
900+
- ``__format__``, because it uses ``__str__``, will also use the value of
901+
the enum member instead of its name
895902

896-
If you do not need/want those limitations, you can either create your own
897-
base class by mixing in the ``int`` or ``str`` type yourself::
903+
If you do not need/want those limitations, you can either create your own
904+
base class by mixing in the ``int`` or ``str`` type yourself::
898905

899-
>>> from enum import Enum
900-
>>> class MyIntEnum(int, Enum):
901-
... pass
906+
>>> from enum import Enum
907+
>>> class MyIntEnum(int, Enum):
908+
... pass
902909

903910
or you can reassign the appropriate :meth:`str`, etc., in your enum::
904911

905-
>>> from enum import IntEnum
906-
>>> class MyIntEnum(IntEnum):
907-
... __str__ = IntEnum.__str__
912+
>>> from enum import IntEnum
913+
>>> class MyIntEnum(IntEnum):
914+
... __str__ = IntEnum.__str__

Doc/library/http.server.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,3 +512,12 @@ Security Considerations
512512
:class:`SimpleHTTPRequestHandler` will follow symbolic links when handling
513513
requests, this makes it possible for files outside of the specified directory
514514
to be served.
515+
516+
Earlier versions of Python did not scrub control characters from the
517+
log messages emitted to stderr from ``python -m http.server`` or the
518+
default :class:`BaseHTTPRequestHandler` ``.log_message``
519+
implementation. This could allow remote clients connecting to your
520+
server to send nefarious control codes to your terminal.
521+
522+
.. versionadded:: 3.12
523+
Control characters are scrubbed in stderr logs.

Doc/library/typing.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,6 +2575,10 @@ Functions and decorators
25752575
assumed to be True or False if it is omitted by the caller.
25762576
* ``kw_only_default`` indicates whether the ``kw_only`` parameter is
25772577
assumed to be True or False if it is omitted by the caller.
2578+
* ``frozen_default`` indicates whether the ``frozen`` parameter is
2579+
assumed to be True or False if it is omitted by the caller.
2580+
2581+
.. versionadded:: 3.12
25782582
* ``field_specifiers`` specifies a static list of supported classes
25792583
or functions that describe fields, similar to ``dataclasses.field()``.
25802584
* Arbitrary other keyword arguments are accepted in order to allow for

Doc/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ sphinx==4.5.0
88
blurb
99

1010
sphinx-lint==0.6.7
11+
sphinxext-opengraph>=0.7.1
1112

1213
# The theme used by the documentation is stored separately, so we need
1314
# to install that as well.

Doc/tools/templates/layout.html

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
<a href="/3/{{ pagename }}{{ file_suffix }}">{% trans %} Python documentation for the current stable release{% endtrans %}</a>.
99
</div>
1010
{%- endif %}
11+
12+
{%- if is_deployment_preview %}
13+
<div id="deployment-preview-warning" style="padding: .5em; text-align: center; background-color: #fff2ba; color: #6a580e;">
14+
<div style="float: right; margin-top: -10px; margin-left: 10px;">
15+
<a href="https://www.netlify.com">
16+
<img src="https://www.netlify.com/img/global/badges/netlify-color-accent.svg" alt="Deploys by Netlify" />
17+
</a>
18+
</div>
19+
{% trans %}This is a deploy preview created from a <a href="{{ repository_url }}/pull/{{ pr_id }}">pull request</a>.
20+
For authoritative documentation, see the {% endtrans %}
21+
<a href="https://docs.python.org/3/{{ pagename }}{{ file_suffix }}">{% trans %} the current stable release{% endtrans %}</a>.
22+
</div>
23+
{%- endif %}
1124
{% endblock %}
1225

1326
{% block rootrellink %}

0 commit comments

Comments
 (0)