Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9bedb8c

Browse files
authored
bpo-37759: Second round of edits to Whatsnew 3.8 (GH-15204) (GH-15240)
(cherry picked from commit66a34d3)
1 parenta150fee commit9bedb8c

File tree

1 file changed

+89
-18
lines changed

1 file changed

+89
-18
lines changed

‎Doc/whatsnew/3.8.rst‎

Lines changed: 89 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
module.
4040
(Contributed by P.Y. Developer in :issue:`12345`.)
4141
42-
This saves the maintainer the effort of going through theMercurial log
42+
This saves the maintainer the effort of going through theGit log
4343
when researching a change.
4444
4545
:Editor: Raymond Hettinger
@@ -59,6 +59,7 @@ notable items not yet covered are:
5959

6060
from datetime import date
6161
from math import cos, radians
62+
from unicodedata import normalize
6263
import re
6364
import math
6465

@@ -383,9 +384,13 @@ Other Language Changes
383384
was lifted.
384385
(Contributed by Serhiy Storchaka in:issue:`32489`.)
385386

386-
* The:class:`int` type now has a new:meth:`~int.as_integer_ratio` method
387-
compatible with the existing:meth:`float.as_integer_ratio` method.
388-
(Contributed by Lisa Roach in:issue:`33073`.)
387+
* The:class:`bool`,:class:`int`, and:class:`fractions.Fraction` types
388+
now have an:meth:`~int.as_integer_ratio` method like that found in
389+
:class:`float` and:class:`decimal.Decimal`. This minor API extension
390+
makes it possible to write ``numerator, denominator =
391+
x.as_integer_ratio()`` and have it work across multiple numeric types.
392+
(Contributed by Lisa Roach in:issue:`33073` and Raymond Hettinger in
393+
:issue:`37819`.)
389394

390395
* Constructors of:class:`int`,:class:`float` and:class:`complex` will now
391396
use the:meth:`~object.__index__` special method, if available and the
@@ -410,19 +415,26 @@ Other Language Changes
410415
never intended to permit more than a bare name on the left-hand side of a
411416
keyword argument assignment term. See:issue:`34641`.
412417

413-
* Iterable unpacking is now allowed without parentheses in:keyword:`yield`
414-
and:keyword:`return` statements.
415-
(Contributed by David Cuthbert and Jordan Chapman in:issue:`32117`.)
418+
* Generalized iterable unpacking in:keyword:`yield` and
419+
:keyword:`return` statements no longer requires enclosing parentheses.
420+
This brings the *yield* and *return* syntax into better agreement with
421+
normal assignment syntax::
422+
423+
>>> def parse(family):
424+
lastname, *members = family.split()
425+
return lastname.upper(), *members
416426

417-
* The compiler now produces a:exc:`SyntaxWarning` in some cases when a comma
418-
is missed before tuple or list. For example::
427+
>>> parse('simpsons homer marge bart lisa sally')
428+
('SIMPSONS', 'homer', 'marge', 'bart', 'lisa', 'sally')
419429

420-
data = [
421-
(1, 2, 3) # oops, missing comma!
422-
(4, 5, 6)
423-
]
424430

425-
(Contributed by Serhiy Storchaka in:issue:`15248`.)
431+
(Contributed by David Cuthbert and Jordan Chapman in:issue:`32117`.)
432+
433+
* When a comma is missed in code such as ``[(10, 20) (30, 40)]``, the
434+
compiler displays a:exc:`SyntaxWarning` with a helpful suggestion.
435+
This improves on just having a:exc:`TypeError` indicating that the
436+
first tuple was not callable. (Contributed by Serhiy Storchaka in
437+
:issue:`15248`.)
426438

427439
* Arithmetic operations between subclasses of:class:`datetime.date` or
428440
:class:`datetime.datetime` and:class:`datetime.timedelta` objects now return
@@ -439,7 +451,25 @@ Other Language Changes
439451
and Windows use this to properly terminate scripts in interactive sessions.
440452
(Contributed by Google via Gregory P. Smith in:issue:`1054041`.)
441453

442-
* Added new ``replace()`` method to the code type (:class:`types.CodeType`).
454+
* Some advanced styles of programming require updating the
455+
:class:`types.CodeType` object for an existing function. Since code
456+
objects are immutable, a new code object needs to be created, one
457+
that is modeled on the existing code object. With 19 parameters,
458+
this was somewhat tedious. Now, the new ``replace()`` method makes
459+
it possible to create a clone with a few altered parameters.
460+
461+
Here's an example that alters the:func:`statistics.mean` function to
462+
prevent the *data* parameter from being used as a keyword argument::
463+
464+
>>> from statistics import mean
465+
>>> mean(data=[10, 20, 90])
466+
40
467+
>>> mean.__code__ = mean.__code__.replace(co_posonlyargcount=1)
468+
>>> mean(data=[10, 20, 90])
469+
Traceback (most recent call last):
470+
...
471+
TypeError: mean() got some positional-only arguments passed as keyword arguments: 'data'
472+
443473
(Contributed by Victor Stinner in:issue:`37032`.)
444474

445475
* For integers, the three-argument form of the:func:`pow` function now
@@ -468,14 +498,55 @@ Other Language Changes
468498

469499
(Contributed by Mark Dickinson in:issue:`36027`.)
470500

471-
* When dictionary comprehensions are evaluated, the key is now evaluated before
472-
the value, as proposed by:pep:`572`.
501+
* Dict comprehensions have been synced-up with dict literals so that the
502+
key is computed first and the value second::
503+
504+
>>> # Dict comprehension
505+
>>> cast = {input('role? '): input('actor? ') for i in range(2)}
506+
role? King Arthur
507+
actor? Chapman
508+
role? Black Knight
509+
actor? Cleese
510+
511+
>>> # Dict literal
512+
>>> cast = {input('role? '): input('actor? ')}
513+
role? Sir Robin
514+
actor? Eric Idle
515+
516+
The guaranteed execution order is helpful with assignment expressions
517+
because variables assigned in the key expression will be available in
518+
the value expression::
519+
520+
>>> names = ['Martin von Löwis', 'Łukasz Langa', 'Walter Dörwald']
521+
>>> {(n := normalize('NFC', name)).casefold() : n for name in names}
522+
{'martin von löwis': 'Martin von Löwis',
523+
'łukasz langa': 'Łukasz Langa',
524+
'walter dörwald': 'Walter Dörwald'}
473525

474526

475527
New Modules
476528
===========
477529

478-
* None yet.
530+
* The new:mod:`importlib.metadata` module provides (provisional) support for
531+
reading metadata from third-party packages. For example, it can extract an
532+
installed package's version number, list of entry points, and more::
533+
534+
>>> # Note following example requires that the popular "requests"
535+
>>> # package has been installed.
536+
>>>
537+
>>> from importlib.metadata import version, requires, files
538+
>>> version('requests')
539+
'2.22.0'
540+
>>> list(requires('requests'))
541+
['chardet (<3.1.0,>=3.0.2)']
542+
>>> list(files('requests'))[:5]
543+
[PackagePath('requests-2.22.0.dist-info/INSTALLER'),
544+
PackagePath('requests-2.22.0.dist-info/LICENSE'),
545+
PackagePath('requests-2.22.0.dist-info/METADATA'),
546+
PackagePath('requests-2.22.0.dist-info/RECORD'),
547+
PackagePath('requests-2.22.0.dist-info/WHEEL')]
548+
549+
(Contributed in:issue:`34632` by Barry Warsaw and Jason R. Coombs.)
479550

480551

481552
Improved Modules

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp