Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fb2d167

Browse files
committed
Issue #11071: Various improvements to whatsnew.
1 parent 810cd34 commit fb2d167

1 file changed

Lines changed: 50 additions & 19 deletions

File tree

Doc/whatsnew/3.2.rst

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,7 @@ Some smaller changes made to the core Python language are:
513513
caused confusion and is no longer needed now that the shortest possible
514514
:func:`repr` is displayed by default:
515515

516+
>>> import math
516517
>>> repr(math.pi)
517518
'3.141592653589793'
518519
>>> str(math.pi)
@@ -633,11 +634,10 @@ Some smaller changes made to the core Python language are:
633634
(See :issue:`10518`.)
634635

635636
* Python's import mechanism can now load modules installed in directories with
636-
non-ASCII characters in the path name:
637+
non-ASCII characters in the path name. This solved an aggravating problem
638+
with home directories for users with non-ASCII characters in their usernames.
637639

638-
>>> import møøse.bites
639-
640-
(Required extensive work by Victor Stinner in :issue:`9425`.)
640+
(Required extensive work by Victor Stinner in :issue:`9425`.)
641641

642642

643643
New, Improved, and Deprecated Modules
@@ -646,14 +646,15 @@ New, Improved, and Deprecated Modules
646646
Python's standard library has undergone significant maintenance efforts and
647647
quality improvements.
648648

649-
The biggest news for Python 3.2 is that the :mod:`email` package and
650-
:mod:`nntplib` modules now work correctly with the bytes/text model in Python 3.
651-
For the first time, there is correct handling of inputs with mixed encodings.
649+
The biggest news for Python 3.2 is that the :mod:`email` package, :mod:`mailbox`
650+
module, and :mod:`nntplib` modules now work correctly with the bytes/text model
651+
in Python 3. For the first time, there is correct handling of message with
652+
mixed encodings.
652653

653654
Throughout the standard library, there has been more careful attention to
654655
encodings and text versus bytes issues. In particular, interactions with the
655-
operating system are now better able to pass non-ASCII data using the Windows
656-
MBCS encoding, locale-aware encodings, or UTF-8.
656+
operating system are now better able to exchange non-ASCII data using the
657+
Windows MBCS encoding, locale-aware encodings, or UTF-8.
657658

658659
Another significant win is the addition of substantially better support for
659660
*SSL* connections and security certificates.
@@ -822,6 +823,7 @@ itertools
822823
* The :mod:`itertools` module has a new :func:`~itertools.accumulate` function
823824
modeled on APL's *scan* operator and Numpy's *accumulate* function:
824825

826+
>>> from itertools import accumulate
825827
>>> list(accumulate(8, 2, 50))
826828
[8, 10, 60]
827829

@@ -911,6 +913,8 @@ back and re-enter the barrier. The barrier fully resets after each cycle.
911913

912914
Example of using barriers::
913915

916+
from threading import Barrier, Thread
917+
914918
def get_votes(site):
915919
ballots = conduct_election(site)
916920
all_polls_closed.wait() # do not count until all polls are closed
@@ -964,7 +968,7 @@ datetime and time
964968
offset and timezone name. This makes it easier to create timezone-aware
965969
datetime objects::
966970

967-
>>> import datetime
971+
>>> from datetime import datetime, timezone
968972

969973
>>> datetime.now(timezone.utc)
970974
datetime.datetime(2010, 12, 8, 21, 4, 2, 923754, tzinfo=datetime.timezone.utc)
@@ -1069,12 +1073,12 @@ These tools make it possible to define an :term:`abstract base class` that
10691073
requires a particular :func:`classmethod` or :func:`staticmethod` to be
10701074
implemented::
10711075

1072-
class Temperature(metaclass=ABCMeta):
1076+
class Temperature(metaclass=abc.ABCMeta):
10731077
@abc.abstractclassmethod
1074-
def from_fahrenheit(self, t):
1078+
def from_fahrenheit(cls, t):
10751079
...
10761080
@abc.abstractclassmethod
1077-
def from_celsius(self, t):
1081+
def from_celsius(cls, t):
10781082
...
10791083

10801084
(Patch submitted by Daniel Urban; :issue:`5867`.)
@@ -1104,8 +1108,8 @@ for slice notation are well-suited to in-place editing::
11041108
>>> change_location(buffer, 1, b'warehouse ')
11051109
>>> change_location(buffer, 0, b'showroom ')
11061110
>>> print(byte_stream.getvalue())
1107-
b'G3805 showroom Main chassis ' ->
1108-
b'X7899 warehouse Reserve cog ' ->
1111+
b'G3805 showroom Main chassis '
1112+
b'X7899 warehouse Reserve cog '
11091113
b'L6988 receiving Primary sprocket'
11101114

11111115
(Contributed by Antoine Pitrou in :issue:`5506`.)
@@ -1425,7 +1429,7 @@ strings, bytes, numbers, tuples, lists, dicts, sets, booleans, and None.
14251429

14261430
::
14271431

1428-
>>> from ast import literal_request
1432+
>>> from ast import literal_eval
14291433

14301434
>>> request = "{'req': 3, 'func': 'pow', 'args': (2, 0.5)}"
14311435
>>> literal_eval(request)
@@ -1491,7 +1495,8 @@ step is non-destructive (the original files are left unchanged).
14911495
>>> import shutil, pprint
14921496

14931497
>>> os.chdir('mydata') # change to the source directory
1494-
>>> f = make_archive('/var/backup/mydata', 'zip') # archive the current directory
1498+
>>> f = shutil.make_archive('/var/backup/mydata',
1499+
'zip') # archive the current directory
14951500
>>> f # show the name of archive
14961501
'/var/backup/mydata.zip'
14971502
>>> os.chdir('tmp') # change to an unpacking
@@ -1505,8 +1510,8 @@ step is non-destructive (the original files are left unchanged).
15051510

15061511
>>> shutil.register_archive_format( # register a new archive format
15071512
name = 'xz',
1508-
function = 'xz.compress',
1509-
extra_args = [('level', 8)],
1513+
function = xz.compress, # callable archiving function
1514+
extra_args = [('level', 8)], # arguments to the function
15101515
description = 'xz compression'
15111516
)
15121517

@@ -1879,6 +1884,32 @@ object. The former returns a string and the latter prints it::
18791884
1: seq
18801885
2: i
18811886

1887+
In addition, the :func:`~dis.dis` function now accepts string arguments
1888+
so that the common idiom ``dis(compile(s, '', 'eval'))`` can be shortened
1889+
to ``dis(compile(s))``::
1890+
1891+
>>> dis('3*x+1 if x%2==1 else x//2')
1892+
1 0 LOAD_NAME 0 (x)
1893+
3 LOAD_CONST 0 (2)
1894+
6 BINARY_MODULO
1895+
7 LOAD_CONST 1 (1)
1896+
10 COMPARE_OP 2 (==)
1897+
13 POP_JUMP_IF_FALSE 28
1898+
16 LOAD_CONST 2 (3)
1899+
19 LOAD_NAME 0 (x)
1900+
22 BINARY_MULTIPLY
1901+
23 LOAD_CONST 1 (1)
1902+
26 BINARY_ADD
1903+
27 RETURN_VALUE
1904+
>> 28 LOAD_NAME 0 (x)
1905+
31 LOAD_CONST 0 (2)
1906+
34 BINARY_FLOOR_DIVIDE
1907+
35 RETURN_VALUE
1908+
1909+
Taken together, these improvements make it easier to explore how CPython is
1910+
implemented and to see for yourself what the language syntax does
1911+
under-the-hood.
1912+
18821913
(Contributed by Nick Coghlan in :issue:`9147`.)
18831914

18841915
dbm

0 commit comments

Comments
 (0)