8000 Merge remote-tracking branch 'origin/master' into bpo_39337_new_3 · shihai1991/cpython@e29ec44 · GitHub
[go: up one dir, main page]

Skip to content

Commit e29ec44

Browse files
committed
Merge remote-tracking branch 'origin/master' into bpo_39337_new_3
* origin/master: (27 commits) bpo-41428: Fix compiler warnings in unionobject.c (pythonGH-22388) bpo-41654: Fix compiler warning in MemoryError_dealloc() (pythonGH-22387) bpo-41833: threading.Thread now uses the target name (pythonGH-22357) bpo-30155: Add macros to get tzinfo from datetime instances (pythonGH-21633) bpo-33822: Update IDLE section of What's New 3.8 (pythonGH-22383) bpo-41844: Add IDLE section to What's New 3.9 (GN-22382) bpo-41841: Prepare IDLE News for 3.10 (pythonGH-22379) bpo-37779 : Add information about the overriding behavior of ConfigParser.read (pythonGH-15177) bpo-40170: Use inline _PyType_HasFeature() function (pythonGH-22375) bpo-40941: Fix stackdepth compiler warnings (pythonGH-22377) bpo-40941: Fix fold_tuple_on_constants() compiler warnings (pythonGH-22378) bpo-40521: Fix PyUnicode_InternInPlace() (pythonGH-22376) bpo-41834: Remove _Py_CheckRecursionLimit variable (pythonGH-22359) bpo-1635741, unicodedata: add ucd_type parameter to UCD_Check() macro (pythonGH-22328) bpo-1635741: Port _lsprof extension to multi-phase init (PEP 489) (pythonGH-22220) bpo-41513: Improve order of adding fractional values. Improve variable names. (pythonGH-22368) bpo-41816: `StrEnum.__str__` is `str.__str__` (pythonGH-22362) bpo-35764: Rewrite the IDLE Calltips doc section (pythonGH-22363) bpo-41810: Reintroduce `types.EllipsisType`, `.NoneType` & `.NotImplementedType` (pythonGH-22336) bpo-41602: raise SIGINT exit code on KeyboardInterrupt from pymain_run_module (python#21956) ...
2 parents a493a35 + d67de0a commit e29ec44

Some content is hidden

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

59 files changed

+857
-371
lines changed

Doc/c-api/datetime.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,11 @@ must not be ``NULL``, and the type is not checked:
185185
186186
Return the microsecond, as an int from 0 through 999999.
187187
188+
.. c:function:: PyObject* PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)
189+
190+
Return the tzinfo (which may be ``None``).
191+
192+
.. versionadded:: 3.10
188193
189194
Macros to extract fields from time objects. The argument must be an instance of
190195
:c:data:`PyDateTime_Time`, including subclasses. The argument must not be ``NULL``,
@@ -209,6 +214,12 @@ and the type is not checked:
209214
210215
Return the microsecond, as an int from 0 through 999999.
211216
217+
.. c:function:: PyObject* PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)
218+
219+
Return the tzinfo (which may be ``None``).
220+
221+
.. versionadded:: 3.10
222+
212223
213224
Macros to extract fields from time delta objects. The argument must be an
214225
instance of :c:data:`PyDateTime_Delta`, including subclasses. The argument must

Doc/library/configparser.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,30 @@ involves the ``DEFAULT`` section which provides default values for all other
135135
sections [1]_. Note also that keys in sections are
136136
case-insensitive and stored in lowercase [1]_.
137137

138+
It is possible to read several configurations into a single
139+
:class:`ConfigParser`, where the most recently added configuration has the
140+
highest priority. Any conflicting keys are taken from the more recent
141+
configuration while the previously existing keys are retained.
142+
143+
.. doctest::
144+
145+
>>> another_config = configparser.ConfigParser()
146+
>>> another_config.read('example.ini')
147+
['example.ini']
148+
>>> another_config['topsecret.server.com']['Port']
149+
'50022'
150+
>>> another_config.read_string("[topsecret.server.com]\nPort=48484")
151+
>>> another_config['topsecret.server.com']['Port']
152+
'48484'
153+
>>> another_config.read_dict({"topsecret.server.com": {"Port": 21212}})
154+
>>> another_config['topsecret.server.com']['Port']
155+
'21212'
156+
>>> another_config['topsecret.server.com']['ForwardX11']
157+
'no'
158+
159+
This behaviour is equivalent to a :meth:`ConfigParser.read` call with several
160+
files passed to the *filenames* parameter.
161+
138162

139163
Supported Datatypes
140164
-------------------

Doc/library/constants.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,21 @@ A small number of constants live in the built-in namespace. They are:
1919

2020
.. data:: None
2121

22-
The sole value of the type ``NoneType``. ``None`` is frequently used to
23-
represent the absence of a value, as when default arguments are not passed to a
24-
function. Assignments to ``None`` are illegal and raise a :exc:`SyntaxError`.
22+
An object frequently used to represent the absence of a value, as when
23+
default arguments are not passed to a function. Assignments to ``None``
24+
are illegal and raise a :exc:`SyntaxError`.
25+
``None`` is the sole instance of the :data:`NoneType` type.
2526

2627

2728
.. data:: NotImplemented
2829

29-
Special value which should be returned by the binary special methods
30+
A special value which should be returned by the binary special methods
3031
(e.g. :meth:`__eq__`, :meth:`__lt__`, :meth:`__add__`, :meth:`__rsub__`,
3132
etc.) to indicate that the operation is not implemented with respect to
3233
the other type; may be returned by the in-place binary special methods
3334
(e.g. :meth:`__imul__`, :meth:`__iand__`, etc.) for the same purpose.
3435
It should not be evaluated in a boolean context.
36+
``NotImplemented`` is the sole instance of the :data:`types.NotImplementedType` type.
3537

3638
.. note::
3739

@@ -59,8 +61,9 @@ A small number of constants live in the built-in namespace. They are:
5961
.. index:: single: ...; ellipsis literal
6062
.. data:: Ellipsis
6163

62-
The same as the ellipsis literal "``...``". Special value used mostly in conjunction
64+
The same as the ellipsis literal "``...``". Special value used mostly in conjunction
6365
with extended slicing syntax for user-defined container data types.
66+
``Ellipsis`` is the sole instance of the :data:`types.EllipsisType` type.
6467

6568

6669
.. data:: __debug__

Doc/library/enum.rst

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ helper, :class:`auto`.
4444
Base class for creating enumerated constants that are also
4545
subclasses of :class:`int`.
4646

47+
.. class:: StrEnum
48+
49+
Base class for creating enumerated constants that are also
50+
subclasses of :class:`str`.
51+
4752
.. class:: IntFlag
4853

4954
Base class for creating enumerated constants that can be combined using
@@ -601,6 +606,30 @@ However, they still can't be compared to standard :class:`Enum` enumerations::
601606
[0, 1]
602607

603608

609+
StrEnum
610+
^^^^^^^
611+
612+
The second variation of :class:`Enum` that is provided is also a subclass of
613+
:class:`str`. Members of a :class:`StrEnum` can be compared to strings;
614+
by extension, string enumerations of different types can also be compared
615+
to each other. :class:`StrEnum` exists to help avoid the problem of getting
616+
an incorrect member::
617+
618+
>>> class Directions(StrEnum):
619+
... NORTH = 'north', # notice the trailing comma
620+
... SOUTH = 'south'
621+
622+
Before :class:`StrEnum`, ``Directions.NORTH`` would have been the :class:`tuple`
623+
``('north',)``.
624+
625+
.. note::
626+
627+
Unlike other Enum's, ``str(StrEnum.member)`` will return the value of the
628+
member instead of the usual ``"EnumClass.member"``.
629+
630+
.. versionadded:: 3.10
631+
632+
604633
IntFlag
605634
^^^^^^^
606635

@@ -901,6 +930,32 @@ Using an auto-numbering :meth:`__new__` would look like::
901930
>>> Color.GREEN.value
902931
2
903932

933+
To make a more general purpose ``AutoNumber``, add ``*args`` to the signature::
934+
935+
>>> class AutoNumber(NoValue):
936+
... def __new__(cls, *args): # this is the only change from above
937+
... value = len(cls.__members__) + 1
938+
... obj = object.__new__(cls)
939+
... obj._value_ = value
940+
... return obj
941+
...
942+
943+
Then when you inherit from ``AutoNumber`` you can write your own ``__init__``
944+
to handle any extra arguments::
945+
946+
>>> class Swatch(AutoNumber):
947+
... def __init__(self, pantone='unknown'):
948+
... self.pantone = pantone
949+
... AUBURN = '3497'
950+
... SEA_GREEN = '1246'
951+
... BLEACHED_CORAL = () # New color, no Pantone code yet!
952+
...
953+
>>> Swatch.SEA_GREEN
954+
<Swatch.SEA_GREEN: 2>
955+
>>> Swatch.SEA_GREEN.pantone
956+
'1246'
957+
>>> Swatch.BLEACHED_CORAL.pantone
958+
'unknown'
904959

905960
.. note::
906961

@@ -1132,6 +1187,20 @@ all-uppercase names for members)::
11321187
.. versionchanged:: 3.5
11331188

11341189

1190+
Creating members that are mixed with other data types
1191+
"""""""""""""""""""""""""""""""""""""""""""""""""""""
1192+
1193+
When subclassing other data types, such as :class:`int` or :class:`str`, with
1194+
an :class:`Enum`, all values after the `=` are passed to that data type's
1195+
constructor. For example::
1196+
1197+
>>> class MyEnum(IntEnum):
1198+
... example = '11', 16 # '11' will be interpreted as a hexadecimal
1199+
... # number
1200+
>>> MyEnum.example
1201+
<MyEnum.example: 17>
1202+
1203+
11351204
Boolean value of ``Enum`` classes and members
11361205
"""""""""""""""""""""""""""""""""""""""""""""
11371206

@@ -1179,3 +1248,13 @@ all named flags and all named combinations of flags that are in the value::
11791248
>>> Color(7) # not named combination
11801249
<Color.CYAN|MAGENTA|BLUE|YELLOW|GREEN|RED: 7>
11811250

1251+
``StrEnum`` and :meth:`str.__str__`
1252+
"""""""""""""""""""""""""""""""""""
1253+
1254+
An important difference between :class:`StrEnum` and other Enums is the
1255+
:meth:`__str__` method; because :class:`StrEnum` members are strings, some
1256+
parts of Python will read the string data directly, while others will call
1257+
:meth:`str()`. To make those two operations have the same result,
1258+
:meth:`StrEnum.__str__` will be the same as :meth:`str.__str__` so that
1259+
``str(StrEnum.member) == StrEnum.member`` is true.
1260+

Doc/library/idle.rst

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -527,30 +527,33 @@ by typing '_' after '.', either before or after the box is opened.
527527
Calltips
528528
^^^^^^^^
529529

530-
A calltip is shown when one types :kbd:`(` after the name of an *accessible*
531-
function. A name expression may include dots and subscripts. A calltip
532-
remains until it is clicked, the cursor is moved out of the argument area,
533-
or :kbd:`)` is typed. When the cursor is in the argument part of a definition,
534-
the menu or shortcut display a calltip.
535-
536-
A calltip consists of the function signature and the first line of the
537-
docstring. For builtins without an accessible signature, the calltip
538-
consists of all lines up the fifth line or the first blank line. These
539-
details may change.
540-
541-
The set of *accessible* functions depends on what modules have been imported
542-
into the user process, including those imported by Idle itself,
543-
and what definitions have been run, all since the last restart.
530+
A calltip is shown automatically when one types :kbd:`(` after the name
531+
of an *accessible* function. A function name expression may include
532+
dots and subscripts. A calltip remains until it is clicked, the cursor
533+
is moved out of the argument area, or :kbd:`)` is typed. Whenever the
534+
cursor is in the argument part of a definition, select Edit and "Show
535+
Call Tip" on the menu or enter its shortcut to display a calltip.
536+
537+
The calltip consists of the function's signature and docstring up to
538+
the latter's first blank line or the fifth non-blank line. (Some builtin
539+
functions lack an accessible signature.) A '/' or '*' in the signature
540+
indicates that the preceding or following arguments are passed by
541+
position or name (keyword) only. Details are subject to change.
542+
543+
In Shell, the accessible functions depends on what modules have been
544+
imported into the user process, including those imported by Idle itself,
545+
and which definitions have been run, all since the last restart.
544546

545547
For example, restart the Shell and enter ``itertools.count(``. A calltip
546-
appears because Idle imports itertools into the user process for its own use.
547-
(This could change.) Enter ``turtle.write(`` and nothing appears. Idle does
548-
not import turtle. The menu or shortcut do nothing either. Enter
549-
``import turtle`` and then ``turtle.write(`` will work.
550-
551-
In an editor, import statements have no effect until one runs the file. One
552-
might want to run a file after writing the import statements at the top,
553-
or immediately run an existing file before editing.
548+
appears because Idle imports itertools into the user process for its own
549+
use. (This could change.) Enter ``turtle.write(`` and nothing appears.
550+
Idle does not itself import turtle. The menu entry and shortcut also do
551+
nothing. Enter ``import turtle``. Thereafter, ``turtle.write(``
552+
will display a calltip.
553+
554+
In an editor, import statements have no effect until one runs the file.
555+
One might want to run a file after writing import statements, after
556+
adding function definitions, or after opening an existing file.
554557

555558
.. _code-context:
556559

Doc/library/threading.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,10 @@ since it is impossible to detect the termination of alien threads.
264264
*target* is the callable object to be invoked by the :meth:`run` method.
265265
Defaults to ``None``, meaning nothing is called.
266266

267-
*name* is the thread name. By default, a unique name is constructed of the
268-
form "Thread-*N*" where *N* is a small decimal number.
267+
*name* is the thread name. By default, a unique name is constructed
268+
of the form "Thread-*N*" where *N* is a small decimal number,
269+
or "Thread-*N* (target)" where "target" is ``target.__name__`` if the
270+
*target* argument is specified.
269271

270272
*args* is the argument tuple for the target invocation. Defaults to ``()``.
271273

@@ -280,6 +282,9 @@ since it is impossible to detect the termination of alien threads.
280282
base class constructor (``Thread.__init__()``) before doing anything else to
281283
the thread.
282284

285+
.. versionchanged:: 3.10
286+
Use the *target* name if *name* argument is omitted.
287+
283288
.. versionchanged:: 3.3
284289
Added the *daemon* argument.
285290

Doc/library/types.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ If you instantiate any of these types, note that signatures may vary between Pyt
103103

104104
Standard names are defined for the following types:
105105

106+
.. data:: NoneType
107+
108+
The type of :data:`None`.
109+
110+
.. versionadded:: 3.10
111+
112+
106113
.. data:: FunctionType
107114
LambdaType
108115

@@ -186,6 +193,13 @@ Standard names are defined for the following types:
186193
.. versionadded:: 3.7
187194

188195

196+
.. data:: NotImplementedType
197+
198+
The type of :data:`NotImplemented`.
199+
200+
.. versionadded:: 3.10
201+
202+
189203
.. data:: MethodDescriptorType
190204

191205
The type of methods of some built-in data types such as :meth:`str.join`.
@@ -236,6 +250,13 @@ Standard names are defined for the following types:
236250
Defaults to ``None``. Previously the attribute was optional.
237251

238252

253+
.. data:: EllipsisType
254+
255+
The type of :data:`Ellipsis`.
256+
257+
.. versionadded:: 3.10
258+
259+
239260
.. class:: TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)
240261

241262
The type of traceback objects such as found in ``sys.exc_info()[2]``.

Doc/whatsnew/3.10.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ Add :data:`sys.orig_argv` attribute: the list of the original command line
150150
arguments passed to the Python executable.
151151
(Contributed by Victor Stinner in :issue:`23427`.)
152152

153+
types
154+
-----
155+
156+
Reintroduced the :data:`types.EllipsisType`, :data:`types.NoneType`
157+
and :data:`types.NotImplementedType` classes, providing a new set
158+
of types readily interpretable by type checkers.
159+
(Contributed by Bas van Beek in :issue:`41810`.)
160+
153161
unittest
154162
--------
155163

@@ -228,9 +236,17 @@ New Features
228236
Python executable.
229237
(Contributed by Victor Stinner in :issue:`23427`.)
230238

239+
* The :c:func:`PyDateTime_DATE_GET_TZINFO` and
240+
:c:func:`PyDateTime_TIME_GET_TZINFO` macros have been added for accessing
241+
the ``tzinfo`` attributes of :class:`datetime.datetime` and
242+
:class:`datetime.time` objects.
243+
(Contributed by Zackery Spytz in :issue:`30155`.)
244+
231245
* Add a c:func:`PyCodec_Unregister` to unregister a codec search function.
232246
(Contributed by Hai Shi in :issue:`41842`.)
233247

248+
=======
249+
234250
Porting to Python 3.10
235251
----------------------
236252

@@ -314,3 +330,7 @@ Removed
314330
* Removed ``PyUnicode_AsUnicodeCopy()``. Please use :c:func:`PyUnicode_AsUCS4Copy` or
315331
:c:func:`PyUnicode_AsWideCharString`
316332
(Contributed by Inada Naoki in :issue:`41103`.)
333+
334+
* Removed ``_Py_CheckRecursionLimit`` variable: it has been replaced by
335+
``ceval.recursion_limit`` of the :c:type:`PyInterpreterState` structure.
336+
(Contributed by Victor Stinner in :issue:`41834`.)

Doc/whatsnew/3.8.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,18 @@ clipboard. Converting strings from Tcl to Python and back now never fails.
870870
(Many people worked on this for eight years but the problem was finally
871871
solved by Serhiy Storchaka in :issue:`13153`.)
872872

873+
New in 3.8.1:
874+
875+
Add option to toggle cursor blink off. (Contributed by Zackery Spytz
876+
in :issue:`4603`.)
877+
878+
Escape key now closes IDLE completion windows. (Contributed by Johnny
879+
Najera in :issue:`38944`.)
880+
873881
The changes above have been backported to 3.7 maintenance releases.
874882

883+
Add keywords to module name completion list. (Contributed by Terry J.
884+
Reedy in :issue:`37765`.)
875885

876886
inspect
877887
-------

0 commit comments

Comments
 (0)
0