-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
bpo-37759: Second round of edits to Whatsnew 3.8 #15204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rhettinger
merged 12 commits into
python:master
from
rhettinger:better_whatsnew_round_two
Aug 12, 2019
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3b9e09b
Add examples for dict evaluation order
rhettinger 4138137
Add test set up
rhettinger 6a25e5a
Explain the replace() method for code objects.
rhettinger f9f511e
Remove stray character
rhettinger 6099153
Edit the entry on the missing comma SyntaxWarning
rhettinger 838d143
Syntax change for iterable unpacking in yield/return statements
rhettinger b325ff7
We're no longer on Mercurial
rhettinger 8a91d0f
Rationale for as_integer_ratio() on int and bool
rhettinger 2392249
Update for Fraction.as_integer_ratio()
rhettinger 5290bfd
Demonstrate the importlib.metadata package
rhettinger fa7a9c9
Fix typo
rhettinger 310ddfb
PEP 8 nit
rhettinger File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ | |
module. | ||
(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. | ||
|
||
:Editor: Raymond Hettinger | ||
|
@@ -59,6 +59,7 @@ notable items not yet covered are: | |
|
||
from datetime import date | ||
from math import cos, radians | ||
from unicodedata import normalize | ||
import re | ||
import math | ||
|
||
|
@@ -383,9 +384,13 @@ Other Language Changes | |
was lifted. | ||
(Contributed by Serhiy Storchaka in :issue:`32489`.) | ||
|
||
* The :class:`int` type now has a new :meth:`~int.as_integer_ratio` method | ||
compatible with the existing :meth:`float.as_integer_ratio` method. | ||
(Contributed by Lisa Roach in :issue:`33073`.) | ||
* The :class:`bool`, :class:`int`, and :class:`fractions.Fraction` types | ||
now have an :meth:`~int.as_integer_ratio` method like that found in | ||
: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 | ||
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 | ||
keyword argument assignment term. See :issue:`34641`. | ||
|
||
* Iterable unpacking is now allowed without parentheses in :keyword:`yield` | ||
and :keyword:`return` statements. | ||
(Contributed by David Cuthbert and Jordan Chapman in :issue:`32117`.) | ||
* Generalized iterable unpacking in :keyword:`yield` and | ||
: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 | ||
|
||
* The compiler now produces a :exc:`SyntaxWarning` in some cases when a comma | ||
is missed before tuple or list. For example:: | ||
>>> parse('simpsons homer marge bart lisa sally') | ||
('SIMPSONS', 'homer', 'marge', 'bart', 'lisa', 'sally') | ||
|
||
data = [ | ||
(1, 2, 3) # oops, missing comma! | ||
(4, 5, 6) | ||
] | ||
|
||
(Contributed by Serhiy Storchaka in :issue:`15248`.) | ||
(Contributed by David Cuthbert and Jordan Chapman in :issue:`32117`.) | ||
|
||
* When a comma is missed in code such as ``[(10, 20) (30, 40)]``, the | ||
compiler displays a :exc:`SyntaxWarning` with a helpful suggestion. | ||
This improves on just having a :exc:`TypeError` indicating that the | ||
first tuple was not callable. (Contributed by Serhiy Storchaka in | ||
:issue:`15248`.) | ||
|
||
* Arithmetic operations between subclasses of :class:`datetime.date` or | ||
: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. | ||
(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`.) | ||
|
||
* 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`.) | ||
|
||
* When dictionary comprehensions are evaluated, the key is now evaluated before | ||
the value, as proposed by :pep:`572`. | ||
* Dict comprehensions have been synced-up with dict literals so that the | ||
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 | ||
=========== | ||
|
||
* The new :mod:`importlib.metadata` module provides (provisional) support for | ||
reading metadata from third-party packages. For example, you can extract an | ||
installed package's version number, list of entry points, and more. See | ||
:issue:`34632` for additional details. | ||
reading metadata from third-party packages. For example, it can extract an | ||
installed package's version number, list of entry points, and more:: | ||
|
||
>>> # 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)'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a bug in importlib_metadata 0.19 and earlier (CPython 3.8b3 and earlier) where only the first requirement would be listed. In the latest codebase, backport to 3.8 just rolling out now, the full list appears:
|
||
>>> 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 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.