Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into bpo_39337_new_3
Browse files Browse the repository at this point in the history
* 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)
  ...
  • Loading branch information
shihai1991 committed Sep 24, 2020
2 parents a493a35 + d67de0a commit e29ec44
Show file tree
Hide file tree
Showing 59 changed files with 857 additions and 371 deletions.
11 changes: 11 additions & 0 deletions Doc/c-api/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ must not be ``NULL``, and the type is not checked:
Return the microsecond, as an int from 0 through 999999.
.. c:function:: PyObject* PyDateTime_DATE_GET_TZINFO(PyDateTime_DateTime *o)
Return the tzinfo (which may be ``None``).
.. versionadded:: 3.10
Macros to extract fields from time objects. The argument must be an instance of
:c:data:`PyDateTime_Time`, including subclasses. The argument must not be ``NULL``,
Expand All @@ -209,6 +214,12 @@ and the type is not checked:
Return the microsecond, as an int from 0 through 999999.
.. c:function:: PyObject* PyDateTime_TIME_GET_TZINFO(PyDateTime_Time *o)
Return the tzinfo (which may be ``None``).
.. versionadded:: 3.10
Macros to extract fields from time delta objects. The argument must be an
instance of :c:data:`PyDateTime_Delta`, including subclasses. The argument must
Expand Down
24 changes: 24 additions & 0 deletions Doc/library/configparser.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ involves the ``DEFAULT`` section which provides default values for all other
sections [1]_. Note also that keys in sections are
case-insensitive and stored in lowercase [1]_.

It is possible to read several configurations into a single
:class:`ConfigParser`, where the most recently added configuration has the
highest priority. Any conflicting keys are taken from the more recent
configuration while the previously existing keys are retained.

.. doctest::

>>> another_config = configparser.ConfigParser()
>>> another_config.read('example.ini')
['example.ini']
>>> another_config['topsecret.server.com']['Port']
'50022'
>>> another_config.read_string("[topsecret.server.com]\nPort=48484")
>>> another_config['topsecret.server.com']['Port']
'48484'
>>> another_config.read_dict({"topsecret.server.com": {"Port": 21212}})
>>> another_config['topsecret.server.com']['Port']
'21212'
>>> another_config['topsecret.server.com']['ForwardX11']
'no'

This behaviour is equivalent to a :meth:`ConfigParser.read` call with several
files passed to the *filenames* parameter.


Supported Datatypes
-------------------
Expand Down
13 changes: 8 additions & 5 deletions Doc/library/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ A small number of constants live in the built-in namespace. They are:

.. data:: None

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


.. data:: NotImplemented

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

.. note::

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

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


.. data:: __debug__
Expand Down
79 changes: 79 additions & 0 deletions Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ helper, :class:`auto`.
Base class for creating enumerated constants that are also
subclasses of :class:`int`.

.. class:: StrEnum

Base class for creating enumerated constants that are also
subclasses of :class:`str`.

.. class:: IntFlag

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


StrEnum
^^^^^^^

The second variation of :class:`Enum` that is provided is also a subclass of
:class:`str`. Members of a :class:`StrEnum` can be compared to strings;
by extension, string enumerations of different types can also be compared
to each other. :class:`StrEnum` exists to help avoid the problem of getting
an incorrect member::

>>> class Directions(StrEnum):
... NORTH = 'north', # notice the trailing comma
... SOUTH = 'south'

Before :class:`StrEnum`, ``Directions.NORTH`` would have been the :class:`tuple`
``('north',)``.

.. note::

Unlike other Enum's, ``str(StrEnum.member)`` will return the value of the
member instead of the usual ``"EnumClass.member"``.

.. versionadded:: 3.10


IntFlag
^^^^^^^

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

To make a more general purpose ``AutoNumber``, add ``*args`` to the signature::

>>> class AutoNumber(NoValue):
... def __new__(cls, *args): # this is the only change from above
... value = len(cls.__members__) + 1
... obj = object.__new__(cls)
... obj._value_ = value
... return obj
...

Then when you inherit from ``AutoNumber`` you can write your own ``__init__``
to handle any extra arguments::

>>> class Swatch(AutoNumber):
... def __init__(self, pantone='unknown'):
... self.pantone = pantone
... AUBURN = '3497'
... SEA_GREEN = '1246'
... BLEACHED_CORAL = () # New color, no Pantone code yet!
...
>>> Swatch.SEA_GREEN
<Swatch.SEA_GREEN: 2>
>>> Swatch.SEA_GREEN.pantone
'1246'
>>> Swatch.BLEACHED_CORAL.pantone
'unknown'

.. note::

Expand Down Expand Up @@ -1132,6 +1187,20 @@ all-uppercase names for members)::
.. versionchanged:: 3.5


Creating members that are mixed with other data types
"""""""""""""""""""""""""""""""""""""""""""""""""""""

When subclassing other data types, such as :class:`int` or :class:`str`, with
an :class:`Enum`, all values after the `=` are passed to that data type's
constructor. For example::

>>> class MyEnum(IntEnum):
... example = '11', 16 # '11' will be interpreted as a hexadecimal
... # number
>>> MyEnum.example
<MyEnum.example: 17>


Boolean value of ``Enum`` classes and members
"""""""""""""""""""""""""""""""""""""""""""""

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

``StrEnum`` and :meth:`str.__str__`
"""""""""""""""""""""""""""""""""""

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

47 changes: 25 additions & 22 deletions Doc/library/idle.rst
Original file line number Diff line number Diff line change
Expand Up @@ -527,30 +527,33 @@ by typing '_' after '.', either before or after the box is opened.
Calltips
^^^^^^^^

A calltip is shown when one types :kbd:`(` after the name of an *accessible*
function. A name expression may include dots and subscripts. A calltip
remains until it is clicked, the cursor is moved out of the argument area,
or :kbd:`)` is typed. When the cursor is in the argument part of a definition,
the menu or shortcut display a calltip.

A calltip consists of the function signature and the first line of the
docstring. For builtins without an accessible signature, the calltip
consists of all lines up the fifth line or the first blank line. These
details may change.

The set of *accessible* functions depends on what modules have been imported
into the user process, including those imported by Idle itself,
and what definitions have been run, all since the last restart.
A calltip is shown automatically when one types :kbd:`(` after the name
of an *accessible* function. A function name expression may include
dots and subscripts. A calltip remains until it is clicked, the cursor
is moved out of the argument area, or :kbd:`)` is typed. Whenever the
cursor is in the argument part of a definition, select Edit and "Show
Call Tip" on the menu or enter its shortcut to display a calltip.

The calltip consists of the function's signature and docstring up to
the latter's first blank line or the fifth non-blank line. (Some builtin
functions lack an accessible signature.) A '/' or '*' in the signature
indicates that the preceding or following arguments are passed by
position or name (keyword) only. Details are subject to change.

In Shell, the accessible functions depends on what modules have been
imported into the user process, including those imported by Idle itself,
and which definitions have been run, all since the last restart.

For example, restart the Shell and enter ``itertools.count(``. A calltip
appears because Idle imports itertools into the user process for its own use.
(This could change.) Enter ``turtle.write(`` and nothing appears. Idle does
not import turtle. The menu or shortcut do nothing either. Enter
``import turtle`` and then ``turtle.write(`` will work.

In an editor, import statements have no effect until one runs the file. One
might want to run a file after writing the import statements at the top,
or immediately run an existing file before editing.
appears because Idle imports itertools into the user process for its own
use. (This could change.) Enter ``turtle.write(`` and nothing appears.
Idle does not itself import turtle. The menu entry and shortcut also do
nothing. Enter ``import turtle``. Thereafter, ``turtle.write(``
will display a calltip.

In an editor, import statements have no effect until one runs the file.
One might want to run a file after writing import statements, after
adding function definitions, or after opening an existing file.

.. _code-context:

Expand Down
9 changes: 7 additions & 2 deletions Doc/library/threading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,10 @@ since it is impossible to detect the termination of alien threads.
*target* is the callable object to be invoked by the :meth:`run` method.
Defaults to ``None``, meaning nothing is called.

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

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

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

.. versionchanged:: 3.10
Use the *target* name if *name* argument is omitted.

.. versionchanged:: 3.3
Added the *daemon* argument.

Expand Down
21 changes: 21 additions & 0 deletions Doc/library/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ If you instantiate any of these types, note that signatures may vary between Pyt

Standard names are defined for the following types:

.. data:: NoneType

The type of :data:`None`.

.. versionadded:: 3.10


.. data:: FunctionType
LambdaType

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


.. data:: NotImplementedType

The type of :data:`NotImplemented`.

.. versionadded:: 3.10


.. data:: MethodDescriptorType

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


.. data:: EllipsisType

The type of :data:`Ellipsis`.

.. versionadded:: 3.10


.. class:: TracebackType(tb_next, tb_frame, tb_lasti, tb_lineno)

The type of traceback objects such as found in ``sys.exc_info()[2]``.
Expand Down
20 changes: 20 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ Add :data:`sys.orig_argv` attribute: the list of the original command line
arguments passed to the Python executable.
(Contributed by Victor Stinner in :issue:`23427`.)

types
-----

Reintroduced the :data:`types.EllipsisType`, :data:`types.NoneType`
and :data:`types.NotImplementedType` classes, providing a new set
of types readily interpretable by type checkers.
(Contributed by Bas van Beek in :issue:`41810`.)

unittest
--------

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

* The :c:func:`PyDateTime_DATE_GET_TZINFO` and
:c:func:`PyDateTime_TIME_GET_TZINFO` macros have been added for accessing
the ``tzinfo`` attributes of :class:`datetime.datetime` and
:class:`datetime.time` objects.
(Contributed by Zackery Spytz in :issue:`30155`.)

* Add a c:func:`PyCodec_Unregister` to unregister a codec search function.
(Contributed by Hai Shi in :issue:`41842`.)

=======

Porting to Python 3.10
----------------------

Expand Down Expand Up @@ -314,3 +330,7 @@ Removed
* Removed ``PyUnicode_AsUnicodeCopy()``. Please use :c:func:`PyUnicode_AsUCS4Copy` or
:c:func:`PyUnicode_AsWideCharString`
(Contributed by Inada Naoki in :issue:`41103`.)

* Removed ``_Py_CheckRecursionLimit`` variable: it has been replaced by
``ceval.recursion_limit`` of the :c:type:`PyInterpreterState` structure.
(Contributed by Victor Stinner in :issue:`41834`.)
10 changes: 10 additions & 0 deletions Doc/whatsnew/3.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -870,8 +870,18 @@ clipboard. Converting strings from Tcl to Python and back now never fails.
(Many people worked on this for eight years but the problem was finally
solved by Serhiy Storchaka in :issue:`13153`.)

New in 3.8.1:

Add option to toggle cursor blink off. (Contributed by Zackery Spytz
in :issue:`4603`.)

Escape key now closes IDLE completion windows. (Contributed by Johnny
Najera in :issue:`38944`.)

The changes above have been backported to 3.7 maintenance releases.

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

inspect
-------
Expand Down
Loading

0 comments on commit e29ec44

Please sign in to comment.