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

Skip to content

Commit 57b197f

Browse files
authored
Merge branch 'main' into eager-tasks-factory
2 parents 57ccce3 + 79b9db9 commit 57b197f

File tree

6 files changed

+56
-43
lines changed

6 files changed

+56
-43
lines changed

Doc/library/dataclasses.rst

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -437,19 +437,19 @@ Module contents
437437

438438
The newly returned object is created by calling the :meth:`~object.__init__`
439439
method of the dataclass. This ensures that
440-
:ref:`__post_init__ <post-init-processing>`, if present, is also called.
440+
:meth:`__post_init__`, if present, is also called.
441441

442442
Init-only variables without default values, if any exist, must be
443443
specified on the call to :func:`replace` so that they can be passed to
444-
:meth:`~object.__init__` and :ref:`__post_init__ <post-init-processing>`.
444+
:meth:`~object.__init__` and :meth:`__post_init__`.
445445

446446
It is an error for ``changes`` to contain any fields that are
447447
defined as having ``init=False``. A :exc:`ValueError` will be raised
448448
in this case.
449449

450450
Be forewarned about how ``init=False`` fields work during a call to
451451
:func:`replace`. They are not copied from the source object, but
452-
rather are initialized in :ref:`__post_init__ <post-init-processing>`, if they're
452+
rather are initialized in :meth:`__post_init__`, if they're
453453
initialized at all. It is expected that ``init=False`` fields will
454454
be rarely and judiciously used. If they are used, it might be wise
455455
to have alternate class constructors, or perhaps a custom
@@ -510,30 +510,31 @@ Module contents
510510
Post-init processing
511511
--------------------
512512

513-
The generated :meth:`~object.__init__` code will call a method named
514-
:meth:`!__post_init__`, if :meth:`!__post_init__` is defined on the
515-
class. It will normally be called as ``self.__post_init__()``.
516-
However, if any ``InitVar`` fields are defined, they will also be
517-
passed to :meth:`!__post_init__` in the order they were defined in the
518-
class. If no :meth:`~object.__init__` method is generated, then
519-
:meth:`!__post_init__` will not automatically be called.
513+
.. function:: __post_init__()
520514

521-
Among other uses, this allows for initializing field values that
522-
depend on one or more other fields. For example::
515+
When defined on the class, it will be called by the generated
516+
:meth:`~object.__init__`, normally as ``self.__post_init__()``.
517+
However, if any ``InitVar`` fields are defined, they will also be
518+
passed to :meth:`__post_init__` in the order they were defined in the
519+
class. If no :meth:`~object.__init__` method is generated, then
520+
:meth:`__post_init__` will not automatically be called.
523521

524-
@dataclass
525-
class C:
526-
a: float
527-
b: float
528-
c: float = field(init=False)
522+
Among other uses, this allows for initializing field values that
523+
depend on one or more other fields. For example::
529524

530-
def __post_init__(self):
531-
self.c = self.a + self.b
525+
@dataclass
526+
class C:
527+
a: float
528+
b: float
529+
c: float = field(init=False)
530+
531+
def __post_init__(self):
532+
self.c = self.a + self.b
532533

533534
The :meth:`~object.__init__` method generated by :func:`dataclass` does not call base
534535
class :meth:`~object.__init__` methods. If the base class has an :meth:`~object.__init__` method
535536
that has to be called, it is common to call this method in a
536-
:meth:`!__post_init__` method::
537+
:meth:`__post_init__` method::
537538

538539
@dataclass
539540
class Rectangle:
@@ -552,7 +553,7 @@ don't need to be called, since the derived dataclass will take care of
552553
initializing all fields of any base class that is a dataclass itself.
553554

554555
See the section below on init-only variables for ways to pass
555-
parameters to :meth:`!__post_init__`. Also see the warning about how
556+
parameters to :meth:`__post_init__`. Also see the warning about how
556557
:func:`replace` handles ``init=False`` fields.
557558

558559
Class variables
@@ -576,7 +577,7 @@ is an ``InitVar``, it is considered a pseudo-field called an init-only
576577
field. As it is not a true field, it is not returned by the
577578
module-level :func:`fields` function. Init-only fields are added as
578579
parameters to the generated :meth:`~object.__init__` method, and are passed to
579-
the optional :ref:`__post_init__ <post-init-processing>` method. They are not otherwise used
580+
the optional :meth:`__post_init__` method. They are not otherwise used
580581
by dataclasses.
581582

582583
For example, suppose a field will be initialized from a database, if a

Doc/library/itertools.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ which incur interpreter overhead.
789789
.. testcode::
790790

791791
import collections
792+
import functools
792793
import math
793794
import operator
794795
import random
@@ -1082,7 +1083,7 @@ The following recipes have a more mathematical flavor:
10821083
# convolve(data, [1, -2, 1]) --> 2nd finite difference (2nd derivative)
10831084
kernel = tuple(kernel)[::-1]
10841085
n = len(kernel)
1085-
padded_signal = chain(repeat(0, n-1), signal, [0] * (n-1))
1086+
padded_signal = chain(repeat(0, n-1), signal, repeat(0, n-1))
10861087
for window in sliding_window(padded_signal, n):
10871088
yield math.sumprod(kernel, window)
10881089

@@ -1092,10 +1093,8 @@ The following recipes have a more mathematical flavor:
10921093
(x - 5) (x + 4) (x - 3) expands to: x³ -4x² -17x + 60
10931094
"""
10941095
# polynomial_from_roots([5, -4, 3]) --> [1, -4, -17, 60]
1095-
expansion = [1]
1096-
for r in roots:
1097-
expansion = convolve(expansion, (1, -r))
1098-
return list(expansion)
1096+
factors = zip(repeat(1), map(operator.neg, roots))
1097+
return list(functools.reduce(convolve, factors, [1]))
10991098

11001099
def polynomial_eval(coefficients, x):
11011100
"""Evaluate a polynomial at a specific value.

Include/internal/pycore_code.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ extern int _PyLineTable_PreviousAddressRange(PyCodeAddressRange *range);
226226

227227
/* Specialization functions */
228228

229-
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *class, PyObject *self,
229+
extern void _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self,
230230
_Py_CODEUNIT *instr, PyObject *name, int load_method);
231231
extern void _Py_Specialize_LoadAttr(PyObject *owner, _Py_CODEUNIT *instr,
232232
PyObject *name);

Lib/test/test_patma.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,6 +3165,19 @@ def f(command): # 0
31653165
self.assertListEqual(self._trace(f, "go x"), [1, 2, 3])
31663166
self.assertListEqual(self._trace(f, "spam"), [1, 2, 3])
31673167

3168+
def test_unreachable_code(self):
3169+
def f(command): # 0
3170+
match command: # 1
3171+
case 1: # 2
3172+
if False: # 3
3173+
return 1 # 4
3174+
case _: # 5
3175+
if False: # 6
3176+
return 0 # 7
3177+
3178+
self.assertListEqual(self._trace(f, 1), [1, 2, 3])
3179+
self.assertListEqual(self._trace(f, 0), [1, 2, 5, 6])
3180+
31683181
def test_parser_deeply_nested_patterns(self):
31693182
# Deeply nested patterns can cause exponential backtracking when parsing.
31703183
# See gh-93671 for more information.

Modules/_datetimemodule.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5144,13 +5144,13 @@ datetime_datetime_now_impl(PyTypeObject *type, PyObject *tz)
51445144
static PyObject *
51455145
datetime_utcnow(PyObject *cls, PyObject *dummy)
51465146
{
5147-
PyErr_WarnEx(
5148-
PyExc_DeprecationWarning,
5149-
"datetime.utcnow() is deprecated and scheduled for removal in a future "
5150-
"version. Use timezone-aware objects to represent datetimes in UTC: "
5151-
"datetime.now(datetime.UTC).",
5152-
2
5153-
);
5147+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
5148+
"datetime.utcnow() is deprecated and scheduled for removal in a "
5149+
"future version. Use timezone-aware objects to represent datetimes "
5150+
"in UTC: datetime.now(datetime.UTC).", 2))
5151+
{
5152+
return NULL;
5153+
}
51545154
return datetime_best_possible(cls, _PyTime_gmtime, Py_None);
51555155
}
51565156

@@ -5187,13 +5187,13 @@ datetime_fromtimestamp(PyObject *cls, PyObject *args, PyObject *kw)
51875187
static PyObject *
51885188
datetime_utcfromtimestamp(PyObject *cls, PyObject *args)
51895189
{
5190-
PyErr_WarnEx(
5191-
PyExc_DeprecationWarning,
5190+
if (PyErr_WarnEx(PyExc_DeprecationWarning,
51925191
"datetime.utcfromtimestamp() is deprecated and scheduled for removal "
51935192
"in a future version. Use timezone-aware objects to represent "
5194-
"datetimes in UTC: datetime.now(datetime.UTC).",
5195-
2
5196-
);
5193+
"datetimes in UTC: datetime.now(datetime.UTC).", 2))
5194+
{
5195+
return NULL;
5196+
}
51975197
PyObject *timestamp;
51985198
PyObject *result = NULL;
51995199

Python/specialize.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ specialize_module_load_attr(
515515
/* Attribute specialization */
516516

517517
void
518-
_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *class, PyObject *self,
518+
_Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *cls, PyObject *self,
519519
_Py_CODEUNIT *instr, PyObject *name, int load_method) {
520520
assert(ENABLE_SPECIALIZATION);
521521
assert(_PyOpcode_Caches[LOAD_SUPER_ATTR] == INLINE_CACHE_ENTRIES_LOAD_SUPER_ATTR);
@@ -528,11 +528,11 @@ _Py_Specialize_LoadSuperAttr(PyObject *global_super, PyObject *class, PyObject *
528528
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_SHADOWED);
529529
goto fail;
530530
}
531-
if (!PyType_Check(class)) {
531+
if (!PyType_Check(cls)) {
532532
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_BAD_CLASS);
533533
goto fail;
534534
}
535-
PyTypeObject *tp = (PyTypeObject *)class;
535+
PyTypeObject *tp = (PyTypeObject *)cls;
536536
PyObject *res = _PySuper_LookupDescr(tp, self, name);
537537
if (res == NULL) {
538538
SPECIALIZATION_FAIL(LOAD_SUPER_ATTR, SPEC_FAIL_SUPER_ERROR_OR_NOT_FOUND);

0 commit comments

Comments
 (0)