Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 043947f

Browse files
committed
Merge remote-tracking branch 'upstream/main' into gh-111140
2 parents b4761be + b4ba0f7 commit 043947f

131 files changed

Lines changed: 1778 additions & 786 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.

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.1.7
3+
rev: v0.2.0
44
hooks:
55
- id: ruff
66
name: Run Ruff on Lib/test/

Doc/c-api/import.rst

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,8 @@ Importing Modules
1313
single: __all__ (package variable)
1414
single: modules (in module sys)
1515
16-
This is a simplified interface to :c:func:`PyImport_ImportModuleEx` below,
17-
leaving the *globals* and *locals* arguments set to ``NULL`` and *level* set
18-
to 0. When the *name*
19-
argument contains a dot (when it specifies a submodule of a package), the
20-
*fromlist* argument is set to the list ``['*']`` so that the return value is the
21-
named module rather than the top-level package containing it as would otherwise
22-
be the case. (Unfortunately, this has an additional side effect when *name* in
23-
fact specifies a subpackage instead of a submodule: the submodules specified in
24-
the package's ``__all__`` variable are loaded.) Return a new reference to the
25-
imported module, or ``NULL`` with an exception set on failure. A failing
26-
import of a module doesn't leave the module in :data:`sys.modules`.
27-
28-
This function always uses absolute imports.
29-
16+
This is a wrapper around :c:func:`PyImport_Import()` which takes a
17+
:c:expr:`const char *` as an argument instead of a :c:expr:`PyObject *`.
3018
3119
.. c:function:: PyObject* PyImport_ImportModuleNoBlock(const char *name)
3220

Doc/glossary.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ Glossary
341341
docstring
342342
A string literal which appears as the first expression in a class,
343343
function or module. While ignored when the suite is executed, it is
344-
recognized by the compiler and put into the :attr:`__doc__` attribute
344+
recognized by the compiler and put into the :attr:`!__doc__` attribute
345345
of the enclosing class, function or module. Since it is available via
346346
introspection, it is the canonical place for documentation of the
347347
object.
@@ -1104,10 +1104,12 @@ Glossary
11041104
The :class:`collections.abc.Sequence` abstract base class
11051105
defines a much richer interface that goes beyond just
11061106
:meth:`~object.__getitem__` and :meth:`~object.__len__`, adding
1107-
:meth:`count`, :meth:`index`, :meth:`~object.__contains__`, and
1107+
:meth:`!count`, :meth:`!index`, :meth:`~object.__contains__`, and
11081108
:meth:`~object.__reversed__`. Types that implement this expanded
11091109
interface can be registered explicitly using
1110-
:func:`~abc.ABCMeta.register`.
1110+
:func:`~abc.ABCMeta.register`. For more documentation on sequence
1111+
methods generally, see
1112+
:ref:`Common Sequence Operations <typesseq-common>`.
11111113

11121114
set comprehension
11131115
A compact way to process all or part of the elements in an iterable and

Doc/howto/enum.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,13 +497,30 @@ the :meth:`~Enum.__repr__` omits the inherited class' name. For example::
497497
>>> Creature.DOG
498498
<Creature.DOG: size='medium', legs=4>
499499

500-
Use the :func:`!dataclass` argument ``repr=False``
500+
Use the :func:`~dataclasses.dataclass` argument ``repr=False``
501501
to use the standard :func:`repr`.
502502

503503
.. versionchanged:: 3.12
504504
Only the dataclass fields are shown in the value area, not the dataclass'
505505
name.
506506

507+
.. note::
508+
509+
Adding :func:`~dataclasses.dataclass` decorator to :class:`Enum`
510+
and its subclasses is not supported. It will not raise any errors,
511+
but it will produce very strange results at runtime, such as members
512+
being equal to each other::
513+
514+
>>> @dataclass # don't do this: it does not make any sense
515+
... class Color(Enum):
516+
... RED = 1
517+
... BLUE = 2
518+
...
519+
>>> Color.RED is Color.BLUE
520+
False
521+
>>> Color.RED == Color.BLUE # problem is here: they should not be equal
522+
True
523+
507524

508525
Pickling
509526
--------

Doc/howto/logging-cookbook.rst

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,30 +1933,28 @@ This dictionary is passed to :func:`~config.dictConfig` to put the configuration
19331933

19341934
LOGGING = {
19351935
'version': 1,
1936-
'disable_existing_loggers': True,
1936+
'disable_existing_loggers': False,
19371937
'formatters': {
19381938
'verbose': {
1939-
'format': '%(levelname)s %(asctime)s %(module)s %(process)d %(thread)d %(message)s'
1939+
'format': '{levelname} {asctime} {module} {process:d} {thread:d} {message}',
1940+
'style': '{',
19401941
},
19411942
'simple': {
1942-
'format': '%(levelname)s %(message)s'
1943+
'format': '{levelname} {message}',
1944+
'style': '{',
19431945
},
19441946
},
19451947
'filters': {
19461948
'special': {
19471949
'()': 'project.logging.SpecialFilter',
19481950
'foo': 'bar',
1949-
}
1951+
},
19501952
},
19511953
'handlers': {
1952-
'null': {
1953-
'level':'DEBUG',
1954-
'class':'django.utils.log.NullHandler',
1955-
},
1956-
'console':{
1957-
'level':'DEBUG',
1958-
'class':'logging.StreamHandler',
1959-
'formatter': 'simple'
1954+
'console': {
1955+
'level': 'INFO',
1956+
'class': 'logging.StreamHandler',
1957+
'formatter': 'simple',
19601958
},
19611959
'mail_admins': {
19621960
'level': 'ERROR',
@@ -1966,9 +1964,8 @@ This dictionary is passed to :func:`~config.dictConfig` to put the configuration
19661964
},
19671965
'loggers': {
19681966
'django': {
1969-
'handlers':['null'],
1967+
'handlers': ['console'],
19701968
'propagate': True,
1971-
'level':'INFO',
19721969
},
19731970
'django.request': {
19741971
'handlers': ['mail_admins'],

Doc/library/asyncio-sync.rst

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ Condition
216216

217217
.. method:: notify(n=1)
218218

219-
Wake up at most *n* tasks (1 by default) waiting on this
220-
condition. The method is no-op if no tasks are waiting.
219+
Wake up *n* tasks (1 by default) waiting on this
220+
condition. If fewer than *n* tasks are waiting they are all awakened.
221221

222222
The lock must be acquired before this method is called and
223223
released shortly after. If called with an *unlocked* lock
@@ -257,12 +257,18 @@ Condition
257257
Once awakened, the Condition re-acquires its lock and this method
258258
returns ``True``.
259259

260+
Note that a task *may* return from this call spuriously,
261+
which is why the caller should always re-check the state
262+
and be prepared to :meth:`wait` again. For this reason, you may
263+
prefer to use :meth:`wait_for` instead.
264+
260265
.. coroutinemethod:: wait_for(predicate)
261266

262267
Wait until a predicate becomes *true*.
263268

264269
The predicate must be a callable which result will be
265-
interpreted as a boolean value. The final value is the
270+
interpreted as a boolean value. The method will repeatedly
271+
:meth:`wait` until the predicate evaluates to *true*. The final value is the
266272
return value.
267273

268274

Doc/library/collections.abc.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ ABC Inherits from Abstract Methods Mi
136136
:class:`Collection` ``__len__`` ``index``, and ``count``
137137

138138
:class:`MutableSequence` :class:`Sequence` ``__getitem__``, Inherited :class:`Sequence` methods and
139-
``__setitem__``, ``append``, ``reverse``, ``extend``, ``pop``,
140-
``__delitem__``, ``remove``, and ``__iadd__``
139+
``__setitem__``, ``append``, ``clear``, ``reverse``, ``extend``,
140+
``__delitem__``, ``pop``, ``remove``, and ``__iadd__``
141141
``__len__``,
142142
``insert``
143143

Doc/library/csv.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ The :mod:`csv` module defines the following classes:
244244

245245
with open('students.csv', 'w', newline='') as csvfile:
246246
writer = csv.writer(csvfile, dialect='unix')
247-
^^^^^^^^^^^^^^
248247

249248

250249
.. class:: excel()

Doc/library/datetime.rst

Lines changed: 55 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ Available Types
130130
.. class:: timedelta
131131
:noindex:
132132

133-
A duration expressing the difference between two :class:`date`, :class:`.time`,
134-
or :class:`.datetime` instances to microsecond resolution.
133+
A duration expressing the difference between two :class:`.datetime`
134+
or :class:`date` instances to microsecond resolution.
135135

136136

137137
.. class:: tzinfo
@@ -203,7 +203,7 @@ objects.
203203
--------------------------
204204

205205
A :class:`timedelta` object represents a duration, the difference between two
206-
dates or times.
206+
:class:`.datetime` or :class:`date` instances.
207207

208208
.. class:: timedelta(days=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0)
209209

@@ -400,30 +400,7 @@ objects (see below).
400400
the :func:`divmod` function. True division and multiplication of a
401401
:class:`timedelta` object by a :class:`float` object are now supported.
402402

403-
404-
Comparisons of :class:`timedelta` objects are supported, with some caveats.
405-
406-
The comparisons ``==`` or ``!=`` *always* return a :class:`bool`, no matter
407-
the type of the compared object::
408-
409-
>>> from datetime import timedelta
410-
>>> delta1 = timedelta(seconds=57)
411-
>>> delta2 = timedelta(hours=25, seconds=2)
412-
>>> delta2 != delta1
413-
True
414-
>>> delta2 == 5
415-
False
416-
417-
For all other comparisons (such as ``<`` and ``>``), when a :class:`timedelta`
418-
object is compared to an object of a different type, :exc:`TypeError`
419-
is raised::
420-
421-
>>> delta2 > delta1
422-
True
423-
>>> delta2 > 5
424-
Traceback (most recent call last):
425-
File "<stdin>", line 1, in <module>
426-
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403+
:class:`timedelta` objects support equality and order comparisons.
427404

428405
In Boolean contexts, a :class:`timedelta` object is
429406
considered to be true if and only if it isn't equal to ``timedelta(0)``.
@@ -614,8 +591,13 @@ Supported operations:
614591
+-------------------------------+----------------------------------------------+
615592
| ``timedelta = date1 - date2`` | \(3) |
616593
+-------------------------------+----------------------------------------------+
617-
| ``date1 < date2`` | *date1* is considered less than *date2* when |
618-
| | *date1* precedes *date2* in time. (4) |
594+
| | ``date1 == date2`` | Equality comparison. (4) |
595+
| | ``date1 != date2`` | |
596+
+-------------------------------+----------------------------------------------+
597+
| | ``date1 < date2`` | Order comparison. (5) |
598+
| | ``date1 > date2`` | |
599+
| | ``date1 <= date2`` | |
600+
| | ``date1 >= date2`` | |
619601
+-------------------------------+----------------------------------------------+
620602

621603
Notes:
@@ -635,15 +617,12 @@ Notes:
635617
timedelta.microseconds are 0, and date2 + timedelta == date1 after.
636618

637619
(4)
620+
:class:`date` objects are equal if they represent the same date.
621+
622+
(5)
623+
*date1* is considered less than *date2* when *date1* precedes *date2* in time.
638624
In other words, ``date1 < date2`` if and only if ``date1.toordinal() <
639-
date2.toordinal()``. Date comparison raises :exc:`TypeError` if
640-
the other comparand isn't also a :class:`date` object. However,
641-
``NotImplemented`` is returned instead if the other comparand has a
642-
:attr:`~date.timetuple` attribute. This hook gives other kinds of date objects a
643-
chance at implementing mixed-type comparison. If not, when a :class:`date`
644-
object is compared to an object of a different type, :exc:`TypeError` is raised
645-
unless the comparison is ``==`` or ``!=``. The latter cases return
646-
:const:`False` or :const:`True`, respectively.
625+
date2.toordinal()``.
647626

648627
In Boolean contexts, all :class:`date` objects are considered to be true.
649628

@@ -1170,8 +1149,13 @@ Supported operations:
11701149
+---------------------------------------+--------------------------------+
11711150
| ``timedelta = datetime1 - datetime2`` | \(3) |
11721151
+---------------------------------------+--------------------------------+
1173-
| ``datetime1 < datetime2`` | Compares :class:`.datetime` to |
1174-
| | :class:`.datetime`. (4) |
1152+
| | ``datetime1 == datetime2`` | Equality comparison. (4) |
1153+
| | ``datetime1 != datetime2`` | |
1154+
+---------------------------------------+--------------------------------+
1155+
| | ``datetime1 < datetime2`` | Order comparison. (5) |
1156+
| | ``datetime1 > datetime2`` | |
1157+
| | ``datetime1 <= datetime2`` | |
1158+
| | ``datetime1 >= datetime2`` | |
11751159
+---------------------------------------+--------------------------------+
11761160

11771161
(1)
@@ -1199,39 +1183,40 @@ Supported operations:
11991183
are done in this case.
12001184

12011185
If both are aware and have different :attr:`~.datetime.tzinfo` attributes, ``a-b`` acts
1202-
as if *a* and *b* were first converted to naive UTC datetimes first. The
1186+
as if *a* and *b* were first converted to naive UTC datetimes. The
12031187
result is ``(a.replace(tzinfo=None) - a.utcoffset()) - (b.replace(tzinfo=None)
12041188
- b.utcoffset())`` except that the implementation never overflows.
12051189

12061190
(4)
1207-
*datetime1* is considered less than *datetime2* when *datetime1* precedes
1208-
*datetime2* in time.
1191+
:class:`.datetime` objects are equal if they represent the same date
1192+
and time, taking into account the time zone.
12091193

1210-
If one comparand is naive and the other is aware, :exc:`TypeError`
1211-
is raised if an order comparison is attempted. For equality
1212-
comparisons, naive instances are never equal to aware instances.
1194+
Naive and aware :class:`!datetime` objects are never equal.
1195+
:class:`!datetime` objects are never equal to :class:`date` objects
1196+
that are not also :class:`!datetime` instances, even if they represent
1197+
the same date.
12131198

1214-
If both comparands are aware, and have the same :attr:`~.datetime.tzinfo` attribute, the
1215-
common :attr:`~.datetime.tzinfo` attribute is ignored and the base datetimes are
1216-
compared. If both comparands are aware and have different :attr:`~.datetime.tzinfo`
1217-
attributes, the comparands are first adjusted by subtracting their UTC
1218-
offsets (obtained from ``self.utcoffset()``).
1199+
If both comparands are aware and have different :attr:`~.datetime.tzinfo`
1200+
attributes, the comparison acts as comparands were first converted to UTC
1201+
datetimes except that the implementation never overflows.
1202+
:class:`!datetime` instances in a repeated interval are never equal to
1203+
:class:`!datetime` instances in other time zone.
12191204

1220-
.. versionchanged:: 3.3
1221-
Equality comparisons between aware and naive :class:`.datetime`
1222-
instances don't raise :exc:`TypeError`.
1205+
(5)
1206+
*datetime1* is considered less than *datetime2* when *datetime1* precedes
1207+
*datetime2* in time, taking into account the time zone.
12231208

1224-
.. note::
1209+
Order comparison between naive and aware :class:`.datetime` objects,
1210+
as well as a :class:`!datetime` object and a :class:`!date` object
1211+
that is not also a :class:`!datetime` instance, raises :exc:`TypeError`.
12251212

1226-
In order to stop comparison from falling back to the default scheme of comparing
1227-
object addresses, datetime comparison normally raises :exc:`TypeError` if the
1228-
other comparand isn't also a :class:`.datetime` object. However,
1229-
``NotImplemented`` is returned instead if the other comparand has a
1230-
:attr:`~.datetime.timetuple` attribute. This hook gives other kinds of date objects a
1231-
chance at implementing mixed-type comparison. If not, when a :class:`.datetime`
1232-
object is compared to an object of a different type, :exc:`TypeError` is raised
1233-
unless the comparison is ``==`` or ``!=``. The latter cases return
1234-
:const:`False` or :const:`True`, respectively.
1213+
If both comparands are aware and have different :attr:`~.datetime.tzinfo`
1214+
attributes, the comparison acts as comparands were first converted to UTC
1215+
datetimes except that the implementation never overflows.
1216+
1217+
.. versionchanged:: 3.3
1218+
Equality comparisons between aware and naive :class:`.datetime`
1219+
instances don't raise :exc:`TypeError`.
12351220

12361221
Instance methods:
12371222

@@ -1766,21 +1751,18 @@ Instance attributes (read-only):
17661751

17671752
.. versionadded:: 3.6
17681753

1769-
:class:`.time` objects support comparison of :class:`.time` to :class:`.time`,
1770-
where *a* is considered less
1771-
than *b* when *a* precedes *b* in time. If one comparand is naive and the other
1772-
is aware, :exc:`TypeError` is raised if an order comparison is attempted. For equality
1773-
comparisons, naive instances are never equal to aware instances.
1754+
:class:`.time` objects support equality and order comparisons,
1755+
where *a* is considered less than *b* when *a* precedes *b* in time.
1756+
1757+
Naive and aware :class:`!time` objects are never equal.
1758+
Order comparison between naive and aware :class:`!time` objects raises
1759+
:exc:`TypeError`.
17741760

17751761
If both comparands are aware, and have
17761762
the same :attr:`~.time.tzinfo` attribute, the common :attr:`!tzinfo` attribute is
17771763
ignored and the base times are compared. If both comparands are aware and
17781764
have different :attr:`!tzinfo` attributes, the comparands are first adjusted by
1779-
subtracting their UTC offsets (obtained from ``self.utcoffset()``). In order
1780-
to stop mixed-type comparisons from falling back to the default comparison by
1781-
object address, when a :class:`.time` object is compared to an object of a
1782-
different type, :exc:`TypeError` is raised unless the comparison is ``==`` or
1783-
``!=``. The latter cases return :const:`False` or :const:`True`, respectively.
1765+
subtracting their UTC offsets (obtained from ``self.utcoffset()``).
17841766

17851767
.. versionchanged:: 3.3
17861768
Equality comparisons between aware and naive :class:`.time` instances

0 commit comments

Comments
 (0)