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

Skip to content

Commit 785dd45

Browse files
committed
Merge remote-tracking branch 'upstream/main' into tvobject
2 parents e952d61 + fcd5fb4 commit 785dd45

39 files changed

Lines changed: 470 additions & 438 deletions

Doc/howto/logging.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ The flow of log event information in loggers and handlers is illustrated in the
418418
following diagram.
419419

420420
.. image:: logging_flow.png
421+
:class: invert-in-dark-mode
421422

422423
Loggers
423424
^^^^^^^

Doc/library/hashlib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ Constructor functions also accept the following tree hashing parameters:
430430

431431
.. figure:: hashlib-blake2-tree.png
432432
:alt: Explanation of tree mode parameters.
433+
:class: invert-in-dark-mode
433434

434435
See section 2.10 in `BLAKE2 specification
435436
<https://www.blake2.net/blake2_20130129.pdf>`_ for comprehensive review of tree

Doc/library/pathlib.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ inherit from pure paths but also provide I/O operations.
2121

2222
.. image:: pathlib-inheritance.png
2323
:align: center
24+
:class: invert-in-dark-mode
2425

2526
If you've never used this module before or just aren't sure which class is
2627
right for your task, :class:`Path` is most likely what you need. It instantiates

Doc/library/typing.rst

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2876,24 +2876,37 @@ Introspection helpers
28762876
if a default value equal to ``None`` was set.
28772877
Now the annotation is returned unchanged.
28782878

2879-
.. function:: get_args(tp)
28802879
.. function:: get_origin(tp)
28812880

2882-
Provide basic introspection for generic types and special typing forms.
2883-
2884-
For a typing object of the form ``X[Y, Z, ...]`` these functions return
2885-
``X`` and ``(Y, Z, ...)``. If ``X`` is a generic alias for a builtin or
2881+
Get the unsubscripted version of a type: for a typing object of the form
2882+
``X[Y, Z, ...]`` return ``X``. If ``X`` is a generic alias for a builtin or
28862883
:mod:`collections` class, it gets normalized to the original class.
2884+
If ``X`` is an instance of :class:`ParamSpecArgs` or :class:`ParamSpecKwargs`,
2885+
return the underlying :class:`ParamSpec`.
2886+
Return ``None`` for unsupported objects.
2887+
Examples::
2888+
2889+
assert get_origin(str) is None
2890+
assert get_origin(Dict[str, int]) is dict
2891+
assert get_origin(Union[int, str]) is Union
2892+
P = ParamSpec('P')
2893+
assert get_origin(P.args) is P
2894+
assert get_origin(P.kwargs) is P
2895+
2896+
.. versionadded:: 3.8
2897+
2898+
.. function:: get_args(tp)
2899+
2900+
Get type arguments with all substitutions performed: for a typing object
2901+
of the form ``X[Y, Z, ...]`` return ``(Y, Z, ...)``.
28872902
If ``X`` is a union or :class:`Literal` contained in another
28882903
generic type, the order of ``(Y, Z, ...)`` may be different from the order
28892904
of the original arguments ``[Y, Z, ...]`` due to type caching.
2890-
For unsupported objects return ``None`` and ``()`` correspondingly.
2905+
Return ``()`` for unsupported objects.
28912906
Examples::
28922907

2893-
assert get_origin(Dict[str, int]) is dict
2908+
assert get_args(int) == ()
28942909
assert get_args(Dict[int, str]) == (int, str)
2895-
2896-
assert get_origin(Union[int, str]) is Union
28972910
assert get_args(Union[int, str]) == (int, str)
28982911

28992912
.. versionadded:: 3.8

Include/cpython/genobject.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
7777

7878
#define PyAsyncGen_CheckExact(op) Py_IS_TYPE((op), &PyAsyncGen_Type)
7979

80+
#define PyAsyncGenASend_CheckExact(op) Py_IS_TYPE((op), &_PyAsyncGenASend_Type)
81+
8082

8183
#undef _PyGenObject_HEAD
8284

Include/internal/pycore_dict_state.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ struct _Py_dict_state {
3838
PyDict_WatchCallback watchers[DICT_MAX_WATCHERS];
3939
};
4040

41+
#define _dict_state_INIT \
42+
{ \
43+
.next_keys_version = 2, \
44+
}
45+
4146

4247
#ifdef __cplusplus
4348
}

Include/internal/pycore_dtoa.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ PyAPI_FUNC(double) _Py_dg_strtod(const char *str, char **ptr);
6464
PyAPI_FUNC(char *) _Py_dg_dtoa(double d, int mode, int ndigits,
6565
int *decpt, int *sign, char **rve);
6666
PyAPI_FUNC(void) _Py_dg_freedtoa(char *s);
67-
PyAPI_FUNC(double) _Py_dg_stdnan(int sign);
68-
PyAPI_FUNC(double) _Py_dg_infinity(int sign);
6967

7068
#endif // _PY_SHORT_FLOAT_REPR == 1
7169

Include/internal/pycore_runtime_init.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ extern PyTypeObject _PyExc_MemoryError;
107107
}, \
108108
}, \
109109
.dtoa = _dtoa_state_INIT(&(INTERP)), \
110-
.dict_state = { \
111-
.next_keys_version = 2, \
112-
}, \
110+
.dict_state = _dict_state_INIT, \
113111
.func_state = { \
114112
.next_version = 1, \
115113
}, \

Include/pymath.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,24 @@
3939
// Return 1 if float or double arg is neither infinite nor NAN, else 0.
4040
#define Py_IS_FINITE(X) isfinite(X)
4141

42-
/* HUGE_VAL is supposed to expand to a positive double infinity. Python
43-
* uses Py_HUGE_VAL instead because some platforms are broken in this
44-
* respect. We used to embed code in pyport.h to try to worm around that,
45-
* but different platforms are broken in conflicting ways. If you're on
46-
* a platform where HUGE_VAL is defined incorrectly, fiddle your Python
47-
* config to #define Py_HUGE_VAL to something that works on your platform.
42+
// Py_INFINITY: Value that evaluates to a positive double infinity.
43+
#ifndef Py_INFINITY
44+
# define Py_INFINITY ((double)INFINITY)
45+
#endif
46+
47+
/* Py_HUGE_VAL should always be the same as Py_INFINITY. But historically
48+
* this was not reliable and Python did not require IEEE floats and C99
49+
* conformity. Prefer Py_INFINITY for new code.
4850
*/
4951
#ifndef Py_HUGE_VAL
5052
# define Py_HUGE_VAL HUGE_VAL
5153
#endif
5254

53-
// Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN).
55+
/* Py_NAN: Value that evaluates to a quiet Not-a-Number (NaN). The sign is
56+
* undefined and normally not relevant, but e.g. fixed for float("nan").
57+
*/
5458
#if !defined(Py_NAN)
55-
# if _Py__has_builtin(__builtin_nan)
56-
// Built-in implementation of the ISO C99 function nan(): quiet NaN.
57-
# define Py_NAN (__builtin_nan(""))
58-
#else
59-
// Use C99 NAN constant: quiet Not-A-Number.
60-
// NAN is a float, Py_NAN is a double: cast to double.
6159
# define Py_NAN ((double)NAN)
62-
# endif
6360
#endif
6461

6562
#endif /* Py_PYMATH_H */

Lib/dataclasses.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1324,11 +1324,18 @@ def _asdict_inner(obj, dict_factory):
13241324
if type(obj) in _ATOMIC_TYPES:
13251325
return obj
13261326
elif _is_dataclass_instance(obj):
1327-
result = []
1328-
for f in fields(obj):
1329-
value = _asdict_inner(getattr(obj, f.name), dict_factory)
1330-
result.append((f.name, value))
1331-
return dict_factory(result)
1327+
# fast path for the common case
1328+
if dict_factory is dict:
1329+
return {
1330+
f.name: _asdict_inner(getattr(obj, f.name), dict)
1331+
for f in fields(obj)
1332+
}
1333+
else:
1334+
result = []
1335+
for f in fields(obj):
1336+
value = _asdict_inner(getattr(obj, f.name), dict_factory)
1337+
result.append((f.name, value))
1338+
return dict_factory(result)
13321339
elif isinstance(obj, tuple) and hasattr(obj, '_fields'):
13331340
# obj is a namedtuple. Recurse into it, but the returned
13341341
# object is another namedtuple of the same type. This is

0 commit comments

Comments
 (0)