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

Skip to content

Commit b8899ec

Browse files
committed
Merge branch 'master' into pegen
2 parents f1afe08 + bba760e commit b8899ec

File tree

96 files changed

+2070
-605
lines changed

Some content is hidden

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

96 files changed

+2070
-605
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Programs/_freeze_importlib
7171
Programs/_testembed
7272
PC/python_nt*.h
7373
PC/pythonnt_rc*.h
74+
Modules/python.exp
7475
PC/*/*.exp
7576
PC/*/*.lib
7677
PC/*/*.bsc

Doc/c-api/init.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
11141114
.. versionadded:: 3.9
11151115
11161116
1117-
.. c:function:: PY_INT64_T PyInterpreterState_GetID(PyInterpreterState *interp)
1117+
.. c:function:: int64_t PyInterpreterState_GetID(PyInterpreterState *interp)
11181118
11191119
Return the interpreter's unique ID. If there was any error in doing
11201120
so then ``-1`` is returned and an error is set.

Doc/library/inspect.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,12 +473,15 @@ Retrieving source code
473473

474474
Get the documentation string for an object, cleaned up with :func:`cleandoc`.
475475
If the documentation string for an object is not provided and the object is
476-
a class, a method, a property or a descriptor, retrieve the documentation
476+
a method, a property or a descriptor, retrieve the documentation
477477
string from the inheritance hierarchy.
478478

479479
.. versionchanged:: 3.5
480480
Documentation strings are now inherited if not overridden.
481481

482+
.. versionchanged:: 3.9
483+
Documentation strings for classes are no longer inherited.
484+
482485

483486
.. function:: getcomments(object)
484487

Doc/library/logging.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,9 @@ The useful mapping keys in a :class:`LogRecord` are given in the section on
608608
attributes are ``default_time_format`` (for the strptime format string)
609609
and ``default_msec_format`` (for appending the millisecond value).
610610

611+
.. versionchanged:: 3.9
612+
The ``default_msec_format`` can be ``None``.
613+
611614
.. method:: formatException(exc_info)
612615

613616
Formats the specified exception information (a standard exception tuple as

Doc/library/os.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ or `the MSDN <https://msdn.microsoft.com/en-us/library/z0kc8e3z.aspx>`_ on Windo
12661266

12671267

12681268
.. function:: sendfile(out_fd, in_fd, offset, count)
1269-
sendfile(out_fd, in_fd, offset, count, [headers], [trailers], flags=0)
1269+
sendfile(out_fd, in_fd, offset, count, headers=(), trailers=(), flags=0)
12701270

12711271
Copy *count* bytes from file descriptor *in_fd* to file descriptor *out_fd*
12721272
starting at *offset*.

Doc/library/pathlib.rst

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,10 @@ Pure paths provide the following methods and properties:
528528
>>> PurePath('a/b.py').match('/*.py')
529529
False
530530

531-
As with other methods, case-sensitivity is observed::
531+
As with other methods, case-sensitivity follows platform defaults::
532532

533+
>>> PurePosixPath('b.py').match('*.PY')
534+
False
533535
>>> PureWindowsPath('b.py').match('*.PY')
534536
True
535537

@@ -569,6 +571,30 @@ Pure paths provide the following methods and properties:
569571
ValueError: PureWindowsPath('c:/') has an empty name
570572

571573

574+
.. method:: PurePath.with_stem(stem)
575+
576+
Return a new path with the :attr:`stem` changed. If the original path
577+
doesn't have a name, ValueError is raised::
578+
579+
>>> p = PureWindowsPath('c:/Downloads/draft.txt')
580+
>>> p.with_stem('final')
581+
PureWindowsPath('c:/Downloads/final.txt')
582+
>>> p = PureWindowsPath('c:/Downloads/pathlib.tar.gz')
583+
>>> p.with_stem('lib')
584+
PureWindowsPath('c:/Downloads/lib.gz')
585+
>>> p = PureWindowsPath('c:/')
586+
>>> p.with_stem('')
587+
Traceback (most recent call last):
588+
File "<stdin>", line 1, in <module>
589+
File "/home/antoine/cpython/default/Lib/pathlib.py", line 861, in with_stem
590+
return self.with_name(stem + self.suffix)
591+
File "/home/antoine/cpython/default/Lib/pathlib.py", line 851, in with_name
592+
raise ValueError("%r has an empty name" % (self,))
593+
ValueError: PureWindowsPath('c:/') has an empty name
594+
595+
.. versionadded:: 3.9
596+
597+
572598
.. method:: PurePath.with_suffix(suffix)
573599

574600
Return a new path with the :attr:`suffix` changed. If the original path

Doc/library/pickle.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,9 +639,9 @@ the methods :meth:`__getstate__` and :meth:`__setstate__`.
639639
At unpickling time, some methods like :meth:`__getattr__`,
640640
:meth:`__getattribute__`, or :meth:`__setattr__` may be called upon the
641641
instance. In case those methods rely on some internal invariant being
642-
true, the type should implement :meth:`__getnewargs__` or
643-
:meth:`__getnewargs_ex__` to establish such an invariant; otherwise,
644-
neither :meth:`__new__` nor :meth:`__init__` will be called.
642+
true, the type should implement :meth:`__new__` to establish such an
643+
invariant, as :meth:`__init__` is not called when unpickling an
644+
instance.
645645

646646
.. index:: pair: copy; protocol
647647

Doc/library/random.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ Bookkeeping functions
111111
as an optional part of the API. When available, :meth:`getrandbits` enables
112112
:meth:`randrange` to handle arbitrarily large ranges.
113113

114+
.. versionchanged:: 3.9
115+
This method now accepts zero for *k*.
116+
117+
118+
.. function:: randbytes(n)
119+
120+
Generate *n* random bytes.
121+
122+
.. versionadded:: 3.9
123+
114124

115125
Functions for integers
116126
----------------------
@@ -220,6 +230,13 @@ Functions for sequences
220230
If the sample size is larger than the population size, a :exc:`ValueError`
221231
is raised.
222232

233+
.. deprecated:: 3.9
234+
In the future, the *population* must be a sequence. Instances of
235+
:class:`set` are no longer supported. The set must first be converted
236+
to a :class:`list` or :class:`tuple`, preferably in a deterministic
237+
order so that the sample is reproducible.
238+
239+
223240
Real-valued distributions
224241
-------------------------
225242

Doc/library/re.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,10 +1617,14 @@ The text categories are specified with regular expressions. The technique is
16171617
to combine those into a single master regular expression and to loop over
16181618
successive matches::
16191619

1620-
import collections
1620+
from typing import NamedTuple
16211621
import re
16221622

1623-
Token = collections.namedtuple('Token', ['type', 'value', 'line', 'column'])
1623+
class Token(NamedTuple):
1624+
type: str
1625+
value: str
1626+
line: int
1627+
column: int
16241628

16251629
def tokenize(code):
16261630
keywords = {'IF', 'THEN', 'ENDIF', 'FOR', 'NEXT', 'GOSUB', 'RETURN'}

Doc/library/statistics.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,16 @@ of applications in statistics.
696696
Set *n* to 100 for percentiles which gives the 99 cuts points that
697697
separate the normal distribution into 100 equal sized groups.
698698

699+
.. method:: NormalDist.zscore(x)
700+
701+
Compute the
702+
`Standard Score <https://www.statisticshowto.com/probability-and-statistics/z-score/>`_
703+
describing *x* in terms of the number of standard deviations
704+
above or below the mean of the normal distribution:
705+
``(x - mean) / stdev``.
706+
707+
.. versionadded:: 3.9
708+
699709
Instances of :class:`NormalDist` support addition, subtraction,
700710
multiplication and division by a constant. These operations
701711
are used for translation and scaling. For example:

Doc/library/unittest.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -910,10 +910,10 @@ Test cases
910910
.. versionadded:: 3.1
911911

912912

913-
.. method:: assertIn(first, second, msg=None)
914-
assertNotIn(first, second, msg=None)
913+
.. method:: assertIn(member, container, msg=None)
914+
assertNotIn(member, container, msg=None)
915915

916-
Test that *first* is (or is not) in *second*.
916+
Test that *member* is (or is not) in *container*.
917917

918918
.. versionadded:: 3.1
919919

Doc/whatsnew/3.9.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,12 @@ Other Language Changes
142142
grammar was much more restrictive. See :pep:`614` for details.
143143
(Contributed by Brandt Bucher in :issue:`39702`.)
144144

145+
* Improved help for the :mod:`typing` module. Docstrings are now shown for
146+
all special forms and special generic aliases (like ``Union`` and ``List``).
147+
Using :func:`help` with generic alias like ``List[int]`` will show the help
148+
for the correspondent concrete type (``list`` in this case).
149+
(Contributed by Serhiy Storchaka in :issue:`40257`.)
150+
145151

146152
New Modules
147153
===========
@@ -200,6 +206,11 @@ and :class:`~concurrent.futures.ProcessPoolExecutor`. This improves
200206
compatibility with subinterpreters and predictability in their shutdown
201207
processes. (Contributed by Kyle Stanley in :issue:`39812`.)
202208

209+
Workers in :class:`~concurrent.futures.ProcessPoolExecutor` are now spawned on
210+
demand, only when there are no available idle workers to reuse. This optimizes
211+
startup overhead and reduces the amount of lost CPU time to idle workers.
212+
(Contributed by Kyle Stanley in :issue:`39207`.)
213+
203214
curses
204215
------
205216

@@ -346,6 +357,19 @@ pprint
346357
:mod:`pprint` can now pretty-print :class:`types.SimpleNamespace`.
347358
(Contributed by Carl Bordum Hansen in :issue:`37376`.)
348359

360+
pydoc
361+
-----
362+
363+
The documentation string is now shown not only for class, function,
364+
method etc, but for any object that has its own ``__doc__`` attribute.
365+
(Contributed by Serhiy Storchaka in :issue:`40257`.)
366+
367+
random
368+
------
369+
370+
Add a new :attr:`random.Random.randbytes` method: generate random bytes.
371+
(Contributed by Victor Stinner in :issue:`40286`.)
372+
349373
signal
350374
------
351375

@@ -798,6 +822,12 @@ Changes in the Python API
798822
:class:`ftplib.FTP_TLS` as a keyword-only parameter, and the default encoding
799823
is changed from Latin-1 to UTF-8 to follow :rfc:`2640`.
800824

825+
* :func:`inspect.getdoc` no longer returns docstring inherited from the type
826+
of the object or from parent class if it is a class if it is not defined
827+
in the object itself.
828+
(Contributed by Serhiy Storchaka in :issue:`40257`.)
829+
830+
801831
CPython bytecode changes
802832
------------------------
803833

Include/internal/pycore_byteswap.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Bytes swap functions, reverse order of bytes:
2+
3+
- _Py_bswap16(uint16_t)
4+
- _Py_bswap32(uint32_t)
5+
- _Py_bswap64(uint64_t)
6+
*/
7+
8+
#ifndef Py_INTERNAL_BSWAP_H
9+
#define Py_INTERNAL_BSWAP_H
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
#ifndef Py_BUILD_CORE
15+
# error "this header requires Py_BUILD_CORE define"
16+
#endif
17+
18+
#if defined(__clang__) || \
19+
(defined(__GNUC__) && \
20+
((__GNUC__ >= 5) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 8)))
21+
/* __builtin_bswap16() is available since GCC 4.8,
22+
__builtin_bswap32() is available since GCC 4.3,
23+
__builtin_bswap64() is available since GCC 4.3. */
24+
# define _PY_HAVE_BUILTIN_BSWAP
25+
#endif
26+
27+
#ifdef _MSC_VER
28+
/* Get _byteswap_ushort(), _byteswap_ulong(), _byteswap_uint64() */
29+
# include <intrin.h>
30+
#endif
31+
32+
static inline uint16_t
33+
_Py_bswap16(uint16_t word)
34+
{
35+
#ifdef _PY_HAVE_BUILTIN_BSWAP
36+
return __builtin_bswap16(word);
37+
#elif defined(_MSC_VER)
38+
Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned short));
39+
return _byteswap_ushort(word);
40+
#else
41+
// Portable implementation which doesn't rely on circular bit shift
42+
return ( ((word & UINT16_C(0x00FF)) << 8)
43+
| ((word & UINT16_C(0xFF00)) >> 8));
44+
#endif
45+
}
46+
47+
static inline uint32_t
48+
_Py_bswap32(uint32_t word)
49+
{
50+
#ifdef _PY_HAVE_BUILTIN_BSWAP
51+
return __builtin_bswap32(word);
52+
#elif defined(_MSC_VER)
53+
Py_BUILD_ASSERT(sizeof(word) == sizeof(unsigned long));
54+
return _byteswap_ulong(word);
55+
#else
56+
// Portable implementation which doesn't rely on circular bit shift
57+
return ( ((word & UINT32_C(0x000000FF)) << 24)
58+
| ((word & UINT32_C(0x0000FF00)) << 8)
59+
| ((word & UINT32_C(0x00FF0000)) >> 8)
60+
| ((word & UINT32_C(0xFF000000)) >> 24));
61+
#endif
62+
}
63+
64+
static inline uint64_t
65+
_Py_bswap64(uint64_t word)
66+
{
67+
#ifdef _PY_HAVE_BUILTIN_BSWAP
68+
return __builtin_bswap64(word);
69+
#elif defined(_MSC_VER)
70+
return _byteswap_uint64(word);
71+
#else
72+
// Portable implementation which doesn't rely on circular bit shift
73+
return ( ((word & UINT64_C(0x00000000000000FF)) << 56)
74+
| ((word & UINT64_C(0x000000000000FF00)) << 40)
75+
| ((word & UINT64_C(0x0000000000FF0000)) << 24)
76+
| ((word & UINT64_C(0x00000000FF000000)) << 8)
77+
| ((word & UINT64_C(0x000000FF00000000)) >> 8)
78+
| ((word & UINT64_C(0x0000FF0000000000)) >> 24)
79+
| ((word & UINT64_C(0x00FF000000000000)) >> 40)
80+
| ((word & UINT64_C(0xFF00000000000000)) >> 56));
81+
#endif
82+
}
83+
84+
85+
#ifdef __cplusplus
86+
}
87+
#endif
88+
#endif /* !Py_INTERNAL_BSWAP_H */
89+

Include/internal/pycore_interp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct _xidregitem {
170170
struct _xidregitem *next;
171171
};
172172

173-
PyAPI_FUNC(struct _is*) _PyInterpreterState_LookUpID(PY_INT64_T);
173+
PyAPI_FUNC(struct _is*) _PyInterpreterState_LookUpID(int64_t);
174174

175175
PyAPI_FUNC(int) _PyInterpreterState_IDInitref(struct _is *);
176176
PyAPI_FUNC(void) _PyInterpreterState_IDIncref(struct _is *);

Include/pyport.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,11 +768,11 @@ extern char * _getpty(int *, int, mode_t, int);
768768
*/
769769

770770
#ifdef WORDS_BIGENDIAN
771-
#define PY_BIG_ENDIAN 1
772-
#define PY_LITTLE_ENDIAN 0
771+
# define PY_BIG_ENDIAN 1
772+
# define PY_LITTLE_ENDIAN 0
773773
#else
774-
#define PY_BIG_ENDIAN 0
775-
#define PY_LITTLE_ENDIAN 1
774+
# define PY_BIG_ENDIAN 0
775+
# define PY_LITTLE_ENDIAN 1
776776
#endif
777777

778778
#ifdef Py_BUILD_CORE

Lib/ast.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,7 @@ def visit_IfExp(self, node):
11491149

11501150
def visit_Set(self, node):
11511151
if not node.elts:
1152-
raise ValueError("Set node should has at least one item")
1152+
raise ValueError("Set node should have at least one item")
11531153
with self.delimit("{", "}"):
11541154
self.interleave(lambda: self.write(", "), self.traverse, node.elts)
11551155

0 commit comments

Comments
 (0)