Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit80f9519

Browse files
committed
Merge branch 'main' into watchers-polish
2 parents40044c0 +985a710 commit80f9519

File tree

266 files changed

+5214
-3393
lines changed

Some content is hidden

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

266 files changed

+5214
-3393
lines changed

‎Doc/_static/og-image.png

14.2 KB
Loading

‎Doc/c-api/refcounting.rst

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
Reference Counting
88
******************
99

10-
The macros in this section are used for managing reference counts of Python
11-
objects.
10+
Thefunctions andmacros in this section are used for managing reference counts
11+
of Pythonobjects.
1212

1313

1414
..c:function:: Py_ssize_tPy_REFCNT(PyObject *o)
@@ -129,6 +129,11 @@ objects.
129129
It is a good idea to use this macro whenever decrementing the reference
130130
count of an object that might be traversed during garbage collection.
131131
132+
..versionchanged::3.12
133+
The macro argument is now only evaluated once. If the argument has side
134+
effects, these are no longer duplicated.
135+
136+
132137
..c:function::voidPy_IncRef(PyObject *o)
133138
134139
Increment the reference count for object *o*. A function version of:c:func:`Py_XINCREF`.
@@ -139,3 +144,40 @@ objects.
139144
140145
Decrement the reference count for object *o*. A function version of:c:func:`Py_XDECREF`.
141146
It can be used for runtime dynamic embedding of Python.
147+
148+
149+
..c:macro:: Py_SETREF(dst, src)
150+
151+
Macro safely decrementing the `dst` reference count and setting `dst` to
152+
`src`.
153+
154+
As in case of:c:func:`Py_CLEAR`, "the obvious" code can be deadly::
155+
156+
Py_DECREF(dst);
157+
dst = src;
158+
159+
The safe way is::
160+
161+
Py_SETREF(dst, src);
162+
163+
That arranges to set `dst` to `src` _before_ decrementing reference count of
164+
*dst* old value, so that any code triggered as a side-effect of `dst`
165+
getting torn down no longer believes `dst` points to a valid object.
166+
167+
..versionadded::3.6
168+
169+
..versionchanged::3.12
170+
The macro arguments are now only evaluated once. If an argument has side
171+
effects, these are no longer duplicated.
172+
173+
174+
..c:macro:: Py_XSETREF(dst, src)
175+
176+
Variant of:c:macro:`Py_SETREF` macro that uses:c:func:`Py_XDECREF` instead
177+
of:c:func:`Py_DECREF`.
178+
179+
..versionadded::3.6
180+
181+
..versionchanged::3.12
182+
The macro arguments are now only evaluated once. If an argument has side
183+
effects, these are no longer duplicated.

‎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+
importsphinxext.opengraph
30+
exceptImportError:
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ And a function to display the chores for a given day::
158158
... for chore, days in chores.items():
159159
... if day in days:
160160
... print(chore)
161+
...
161162
>>> show_chores(chores_for_ethan, Weekday.SATURDAY)
162163
answer SO questions
163164

@@ -459,6 +460,31 @@ sense to allow sharing some common behavior between a group of enumerations.
459460
(See `OrderedEnum`_ for an example.)
460461

461462

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

@@ -687,6 +713,7 @@ It is also possible to name the combinations::
687713
... W = 2
688714
... X = 1
689715
... RWX = 7
716+
...
690717
>>> Perm.RWX
691718
<Perm.RWX: 7>
692719
>>> ~Perm.RWX

‎Doc/library/argparse.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,7 @@ arguments they contain. For example::
565565

566566
>>> with open('args.txt', 'w', encoding=sys.getfilesystemencoding()) as fp:
567567
... fp.write('-f\nbar')
568+
...
568569
>>> parser = argparse.ArgumentParser(fromfile_prefix_chars='@')
569570
>>> parser.add_argument('-f')
570571
>>> parser.parse_args(['-f', 'foo', '@args.txt'])

‎Doc/library/asyncio-eventloop.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ an event loop:
4343

4444
Get the current event loop.
4545

46-
If there is no current event loop set in the current OS thread,
47-
the OS thread is main, and:func:`set_event_loop` has not yet
48-
been called, asyncio will create a new event loop and set it as the
49-
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()``.
5052

5153
Because this function has rather complex behavior (especially
5254
when custom event loop policies are in use), using the
@@ -57,11 +59,11 @@ an event loop:
5759
instead of using these lower level functions to manually create and close an
5860
event loop.
5961

60-
..deprecated::3.10
61-
Emits a deprecation warning if there is no running event loop.
62-
In future Python releases, this function may become an alias of
63-
:func:`get_running_loop` and will accordingly raise a
64-
:exc:`RuntimeError` if there is no running event 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.
6567

6668
..function::set_event_loop(loop)
6769

‎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 orcurrentvia 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/bz2.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,11 @@ Writing and reading a bzip2-compressed file in binary mode:
320320
>>>with bz2.open("myfile.bz2","wb")as f:
321321
...# Write compressed data to file
322322
...unused= f.write(data)
323+
...
323324
>>>with bz2.open("myfile.bz2","rb")as f:
324325
...# Decompress data from file
325326
...content= f.read()
327+
...
326328
>>>content== data# Check equality to original object after round-trip
327329
True
328330

‎Doc/library/collections.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ For example::
229229
>>> cnt = Counter()
230230
>>> for word in ['red', 'blue', 'red', 'green', 'blue', 'blue']:
231231
... cnt[word] += 1
232+
...
232233
>>> cnt
233234
Counter({'blue': 3, 'red': 2, 'green': 1})
234235

@@ -818,6 +819,7 @@ zero):
818819

819820
>>>defconstant_factory(value):
820821
...returnlambda: value
822+
...
821823
>>>d= defaultdict(constant_factory('<missing>'))
822824
>>>d.update(name='John',action='ran')
823825
>>>'%(name)s%(action)s to%(object)s'% d

‎Doc/library/datetime.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,7 @@ Example of counting days to an event::
765765
>>> my_birthday = date(today.year, 6, 24)
766766
>>> if my_birthday < today:
767767
... my_birthday = my_birthday.replace(year=today.year + 1)
768+
...
768769
>>> my_birthday
769770
datetime.date(2008, 6, 24)
770771
>>> time_to_birthday = abs(my_birthday - today)
@@ -2601,7 +2602,7 @@ Notes:
26012602

26022603
(9)
26032604
When used with the:meth:`strptime` method, the leading zero is optional
2604-
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%J``, ``%U``,
2605+
for formats ``%d``, ``%m``, ``%H``, ``%I``, ``%M``, ``%S``, ``%j``, ``%U``,
26052606
``%W``, and ``%V``. Format ``%y`` does require a leading zero.
26062607

26072608
..rubric::Footnotes

‎Doc/library/decimal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,6 +2057,7 @@ to handle the :meth:`quantize` step:
20572057

20582058
>>>defmul(x,y,fp=TWOPLACES):
20592059
...return (x* y).quantize(fp)
2060+
...
20602061
>>>defdiv(x,y,fp=TWOPLACES):
20612062
...return (x/ y).quantize(fp)
20622063

‎Doc/library/doctest.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ The fine print:
351351

352352
>>> def f(x):
353353
... r'''Backslashes in a raw docstring: m\n'''
354+
...
354355
>>> print(f.__doc__)
355356
Backslashes in a raw docstring: m\n
356357

@@ -360,6 +361,7 @@ The fine print:
360361

361362
>>> def f(x):
362363
... '''Backslashes in a raw docstring: m\\n'''
364+
...
363365
>>> print(f.__doc__)
364366
Backslashes in a raw docstring: m\n
365367

@@ -1055,7 +1057,7 @@ from text files and modules with doctests:
10551057
from a text file using:func:`DocFileSuite`.
10561058

10571059

1058-
..function::DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None, setUp=None, tearDown=None, checker=None)
1060+
..function::DocTestSuite(module=None, globs=None, extraglobs=None, test_finder=None, setUp=None, tearDown=None,optionflags=0,checker=None)
10591061

10601062
Convert doctest tests for a module to a:class:`unittest.TestSuite`.
10611063

‎Doc/library/email.policy.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ file on disk and pass it to the system ``sendmail`` program on a Unix system:
9797
>>>from subprocessimport Popen,PIPE
9898
>>>withopen('mymsg.txt','rb')as f:
9999
...msg= message_from_binary_file(f,policy=policy.default)
100+
...
100101
>>>p= Popen(['sendmail', msg['To'].addresses[0]],stdin=PIPE)
101102
>>>g= BytesGenerator(p.stdin,policy=msg.policy.clone(linesep='\r\n'))
102103
>>>g.flatten(msg)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp