bpo-37759: Second round of edits to Whatsnew 3.8 (GH-15204)
This commit is contained in:
parent
c1aeb292d2
commit
66a34d35e4
|
@ -39,7 +39,7 @@
|
||||||
module.
|
module.
|
||||||
(Contributed by P.Y. Developer in :issue:`12345`.)
|
(Contributed by P.Y. Developer in :issue:`12345`.)
|
||||||
|
|
||||||
This saves the maintainer the effort of going through the Mercurial log
|
This saves the maintainer the effort of going through the Git log
|
||||||
when researching a change.
|
when researching a change.
|
||||||
|
|
||||||
:Editor: Raymond Hettinger
|
:Editor: Raymond Hettinger
|
||||||
|
@ -59,6 +59,7 @@ notable items not yet covered are:
|
||||||
|
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from math import cos, radians
|
from math import cos, radians
|
||||||
|
from unicodedata import normalize
|
||||||
import re
|
import re
|
||||||
import math
|
import math
|
||||||
|
|
||||||
|
@ -383,9 +384,13 @@ Other Language Changes
|
||||||
was lifted.
|
was lifted.
|
||||||
(Contributed by Serhiy Storchaka in :issue:`32489`.)
|
(Contributed by Serhiy Storchaka in :issue:`32489`.)
|
||||||
|
|
||||||
* The :class:`int` type now has a new :meth:`~int.as_integer_ratio` method
|
* The :class:`bool`, :class:`int`, and :class:`fractions.Fraction` types
|
||||||
compatible with the existing :meth:`float.as_integer_ratio` method.
|
now have an :meth:`~int.as_integer_ratio` method like that found in
|
||||||
(Contributed by Lisa Roach in :issue:`33073`.)
|
:class:`float` and :class:`decimal.Decimal`. This minor API extension
|
||||||
|
makes it possible to write ``numerator, denominator =
|
||||||
|
x.as_integer_ratio()`` and have it work across multiple numeric types.
|
||||||
|
(Contributed by Lisa Roach in :issue:`33073` and Raymond Hettinger in
|
||||||
|
:issue:`37819`.)
|
||||||
|
|
||||||
* Constructors of :class:`int`, :class:`float` and :class:`complex` will now
|
* Constructors of :class:`int`, :class:`float` and :class:`complex` will now
|
||||||
use the :meth:`~object.__index__` special method, if available and the
|
use the :meth:`~object.__index__` special method, if available and the
|
||||||
|
@ -410,19 +415,26 @@ Other Language Changes
|
||||||
never intended to permit more than a bare name on the left-hand side of a
|
never intended to permit more than a bare name on the left-hand side of a
|
||||||
keyword argument assignment term. See :issue:`34641`.
|
keyword argument assignment term. See :issue:`34641`.
|
||||||
|
|
||||||
* Iterable unpacking is now allowed without parentheses in :keyword:`yield`
|
* Generalized iterable unpacking in :keyword:`yield` and
|
||||||
and :keyword:`return` statements.
|
:keyword:`return` statements no longer requires enclosing parentheses.
|
||||||
|
This brings the *yield* and *return* syntax into better agreement with
|
||||||
|
normal assignment syntax::
|
||||||
|
|
||||||
|
>>> def parse(family):
|
||||||
|
lastname, *members = family.split()
|
||||||
|
return lastname.upper(), *members
|
||||||
|
|
||||||
|
>>> parse('simpsons homer marge bart lisa sally')
|
||||||
|
('SIMPSONS', 'homer', 'marge', 'bart', 'lisa', 'sally')
|
||||||
|
|
||||||
|
|
||||||
(Contributed by David Cuthbert and Jordan Chapman in :issue:`32117`.)
|
(Contributed by David Cuthbert and Jordan Chapman in :issue:`32117`.)
|
||||||
|
|
||||||
* The compiler now produces a :exc:`SyntaxWarning` in some cases when a comma
|
* When a comma is missed in code such as ``[(10, 20) (30, 40)]``, the
|
||||||
is missed before tuple or list. For example::
|
compiler displays a :exc:`SyntaxWarning` with a helpful suggestion.
|
||||||
|
This improves on just having a :exc:`TypeError` indicating that the
|
||||||
data = [
|
first tuple was not callable. (Contributed by Serhiy Storchaka in
|
||||||
(1, 2, 3) # oops, missing comma!
|
:issue:`15248`.)
|
||||||
(4, 5, 6)
|
|
||||||
]
|
|
||||||
|
|
||||||
(Contributed by Serhiy Storchaka in :issue:`15248`.)
|
|
||||||
|
|
||||||
* Arithmetic operations between subclasses of :class:`datetime.date` or
|
* Arithmetic operations between subclasses of :class:`datetime.date` or
|
||||||
:class:`datetime.datetime` and :class:`datetime.timedelta` objects now return
|
:class:`datetime.datetime` and :class:`datetime.timedelta` objects now return
|
||||||
|
@ -439,7 +451,25 @@ Other Language Changes
|
||||||
and Windows use this to properly terminate scripts in interactive sessions.
|
and Windows use this to properly terminate scripts in interactive sessions.
|
||||||
(Contributed by Google via Gregory P. Smith in :issue:`1054041`.)
|
(Contributed by Google via Gregory P. Smith in :issue:`1054041`.)
|
||||||
|
|
||||||
* Added new ``replace()`` method to the code type (:class:`types.CodeType`).
|
* Some advanced styles of programming require updating the
|
||||||
|
:class:`types.CodeType` object for an existing function. Since code
|
||||||
|
objects are immutable, a new code object needs to be created, one
|
||||||
|
that is modeled on the existing code object. With 19 parameters,
|
||||||
|
this was somewhat tedious. Now, the new ``replace()`` method makes
|
||||||
|
it possible to create a clone with a few altered parameters.
|
||||||
|
|
||||||
|
Here's an example that alters the :func:`statistics.mean` function to
|
||||||
|
prevent the *data* parameter from being used as a keyword argument::
|
||||||
|
|
||||||
|
>>> from statistics import mean
|
||||||
|
>>> mean(data=[10, 20, 90])
|
||||||
|
40
|
||||||
|
>>> mean.__code__ = mean.__code__.replace(co_posonlyargcount=1)
|
||||||
|
>>> mean(data=[10, 20, 90])
|
||||||
|
Traceback (most recent call last):
|
||||||
|
...
|
||||||
|
TypeError: mean() got some positional-only arguments passed as keyword arguments: 'data'
|
||||||
|
|
||||||
(Contributed by Victor Stinner in :issue:`37032`.)
|
(Contributed by Victor Stinner in :issue:`37032`.)
|
||||||
|
|
||||||
* For integers, the three-argument form of the :func:`pow` function now
|
* For integers, the three-argument form of the :func:`pow` function now
|
||||||
|
@ -468,17 +498,55 @@ Other Language Changes
|
||||||
|
|
||||||
(Contributed by Mark Dickinson in :issue:`36027`.)
|
(Contributed by Mark Dickinson in :issue:`36027`.)
|
||||||
|
|
||||||
* When dictionary comprehensions are evaluated, the key is now evaluated before
|
* Dict comprehensions have been synced-up with dict literals so that the
|
||||||
the value, as proposed by :pep:`572`.
|
key is computed first and the value second::
|
||||||
|
|
||||||
|
>>> # Dict comprehension
|
||||||
|
>>> cast = {input('role? '): input('actor? ') for i in range(2)}
|
||||||
|
role? King Arthur
|
||||||
|
actor? Chapman
|
||||||
|
role? Black Knight
|
||||||
|
actor? Cleese
|
||||||
|
|
||||||
|
>>> # Dict literal
|
||||||
|
>>> cast = {input('role? '): input('actor? ')}
|
||||||
|
role? Sir Robin
|
||||||
|
actor? Eric Idle
|
||||||
|
|
||||||
|
The guaranteed execution order is helpful with assignment expressions
|
||||||
|
because variables assigned in the key expression will be available in
|
||||||
|
the value expression::
|
||||||
|
|
||||||
|
>>> names = ['Martin von Löwis', 'Łukasz Langa', 'Walter Dörwald']
|
||||||
|
>>> {(n := normalize('NFC', name)).casefold() : n for name in names}
|
||||||
|
{'martin von löwis': 'Martin von Löwis',
|
||||||
|
'łukasz langa': 'Łukasz Langa',
|
||||||
|
'walter dörwald': 'Walter Dörwald'}
|
||||||
|
|
||||||
|
|
||||||
New Modules
|
New Modules
|
||||||
===========
|
===========
|
||||||
|
|
||||||
* The new :mod:`importlib.metadata` module provides (provisional) support for
|
* The new :mod:`importlib.metadata` module provides (provisional) support for
|
||||||
reading metadata from third-party packages. For example, you can extract an
|
reading metadata from third-party packages. For example, it can extract an
|
||||||
installed package's version number, list of entry points, and more. See
|
installed package's version number, list of entry points, and more::
|
||||||
:issue:`34632` for additional details.
|
|
||||||
|
>>> # Note following example requires that the popular "requests"
|
||||||
|
>>> # package has been installed.
|
||||||
|
>>>
|
||||||
|
>>> from importlib.metadata import version, requires, files
|
||||||
|
>>> version('requests')
|
||||||
|
'2.22.0'
|
||||||
|
>>> list(requires('requests'))
|
||||||
|
['chardet (<3.1.0,>=3.0.2)']
|
||||||
|
>>> list(files('requests'))[:5]
|
||||||
|
[PackagePath('requests-2.22.0.dist-info/INSTALLER'),
|
||||||
|
PackagePath('requests-2.22.0.dist-info/LICENSE'),
|
||||||
|
PackagePath('requests-2.22.0.dist-info/METADATA'),
|
||||||
|
PackagePath('requests-2.22.0.dist-info/RECORD'),
|
||||||
|
PackagePath('requests-2.22.0.dist-info/WHEEL')]
|
||||||
|
|
||||||
|
(Contributed in :issue:`34632` by Barry Warsaw and Jason R. Coombs.)
|
||||||
|
|
||||||
|
|
||||||
Improved Modules
|
Improved Modules
|
||||||
|
|
Loading…
Reference in New Issue