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

Skip to content

Commit 92ba286

Browse files
committed
More updates to whatsnew3.2
1 parent 6db7730 commit 92ba286

1 file changed

Lines changed: 91 additions & 46 deletions

File tree

Doc/whatsnew/3.2.rst

Lines changed: 91 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,18 @@ This article explains the new features in Python 3.2, compared to 3.1.
5353
PEP 391: Dictionary Based Configuration for Logging
5454
====================================================
5555

56-
The :mod:`logging` module had two ways of configuring the module, either by calling
57-
functions for each option or by reading an external file saved in a :mod:`ConfigParser`
58-
format. Those options did not provide the flexibility to create configurations
59-
from JSON or YAML files and they did not support incremental configuration, which
60-
is needed for specifying logger options from a command line.
56+
The :mod:`logging` module provided two kinds of configuration, one style with
57+
function calls for each option or another style driven by an external file saved
58+
in a :mod:`ConfigParser` format. Those options did not provide the flexibility
59+
to create configurations from JSON or YAML files, nor they did not support
60+
incremental configuration, which is needed for specifying logger options from a
61+
command line.
6162

6263
To support a more flexible style, the module now offers
63-
:func:`logging.config.dictConfig` to use dictionaries to specify logger
64-
configuration (including formatters, handlers, filters, and loggers). For
65-
example:
66-
67-
>>> import logging.config
68-
>>> logging.config.dictConfig(json.load(open('log.cfg', 'rb')))
69-
70-
The above fragment configures logging from a JSON-encoded dictionary stored in a
71-
file called "log.cfg". Here's a working example of a configuration dictionary::
64+
:func:`logging.config.dictConfig` for specifying logging configuration with
65+
plain Python dictionaries. The configuration options include formatters,
66+
handlers, filters, and loggers. Here's a working example of a configuration
67+
dictionary::
7268

7369
{"version": 1,
7470
"formatters": {"brief": {"format": "%(levelname)-8s: %(name)-15s: %(message)s"},
@@ -87,6 +83,15 @@ file called "log.cfg". Here's a working example of a configuration dictionary::
8783
},
8884
"root": {"level": "DEBUG", "handlers": ["console", "console_priority"]}}
8985

86+
87+
If that dictionary is stored in a file called "conf.json", it can loaded
88+
and called with code like this::
89+
90+
>>> import logging.config
91+
>>> logging.config.dictConfig(json.load(open('conf.json', 'rb')))
92+
>>> logging.info("Transaction completed normally")
93+
>>> logging.critical("Abnormal termination")
94+
9095
.. seealso::
9196

9297
:pep:`391` - Dictionary Based Configuration for Logging
@@ -119,16 +124,16 @@ aspects that are visible to the programmer:
119124
* Imported modules now have a :attr:`__cached__` attribute which stores the name
120125
of the actual file that was imported:
121126

122-
>>> import collections
123-
>>> collections.__cached__
124-
'c:/py32/lib/__pycache__/collections.cpython-32.pyc'
127+
>>> import collections
128+
>>> collections.__cached__
129+
'c:/py32/lib/__pycache__/collections.cpython-32.pyc'
125130

126131
* The tag that is unique to each interpreter is accessible from the :mod:`imp`
127132
module:
128133

129-
>>> import imp
130-
>>> imp.get_tag()
131-
'cpython-32'
134+
>>> import imp
135+
>>> imp.get_tag()
136+
'cpython-32'
132137

133138
* Scripts that try to deduce source filename from the imported file now need to
134139
be smarter. It is no longer sufficient to simply strip the "c" from a ".pyc"
@@ -199,10 +204,10 @@ Some smaller changes made to the core Python language are:
199204
caused confusion and is no longer needed now that the shortest possible
200205
:func:`repr` is displayed by default:
201206

202-
>>> repr(math.pi)
203-
'3.141592653589793'
204-
>>> str(math.pi)
205-
'3.141592653589793'
207+
>>> repr(math.pi)
208+
'3.141592653589793'
209+
>>> str(math.pi)
210+
'3.141592653589793'
206211

207212
(Proposed and implemented by Mark Dickinson; :issue:`9337`.)
208213

@@ -218,8 +223,22 @@ Some smaller changes made to the core Python language are:
218223
* The :mod:`abc` module now supports :func:`~abc.abstractclassmethod` and
219224
:func:`~abc.abstractstaticmethod`.
220225

221-
(:issue:`5867`.)
226+
(Patch submitted by Daniel Urban; :issue:`5867`.)
227+
228+
* A warning message will now get printed at interpreter shutdown if the
229+
:data:`gc.garbage` list isn't empty. This is meant to make the programmer
230+
aware that their code contains object finalization issues.
231+
232+
(Added by Antoine Pitrou; :issue:`477863`.)
233+
234+
* Mark Dickinson crafted an elegant and efficient scheme for assuring that
235+
different numeric datatypes will have the same hash value whenever their
236+
actual values are equal::
222237

238+
>>> assert hash(Fraction(3, 2)) == hash(1.5) == \
239+
hash(Decimal("1.5")) == hash(complex(1.5, 0))
240+
241+
(See :issue:`8188`.)
223242

224243
New, Improved, and Deprecated Modules
225244
=====================================
@@ -263,26 +282,28 @@ New, Improved, and Deprecated Modules
263282

264283
* The :class:`ftplib.FTP` class now supports the context manager protocol to
265284
unconditionally consume :exc:`socket.error` exceptions and to close the FTP
266-
connection when done:
285+
connection when done::
267286

268-
>>> from ftplib import FTP
269-
>>> with FTP("ftp1.at.proftpd.org") as ftp:
270-
... ftp.login()
271-
... ftp.dir()
272-
...
273-
'230 Anonymous login ok, restrictions apply.'
274-
dr-xr-xr-x 9 ftp ftp 154 May 6 10:43 .
275-
dr-xr-xr-x 9 ftp ftp 154 May 6 10:43 ..
276-
dr-xr-xr-x 5 ftp ftp 4096 May 6 10:43 CentOS
277-
dr-xr-xr-x 3 ftp ftp 18 Jul 10 2008 Fedora
287+
>>> from ftplib import FTP
288+
>>> with FTP("ftp1.at.proftpd.org") as ftp:
289+
... ftp.login()
290+
... ftp.dir()
291+
...
292+
'230 Anonymous login ok, restrictions apply.'
293+
dr-xr-xr-x 9 ftp ftp 154 May 6 10:43 .
294+
dr-xr-xr-x 9 ftp ftp 154 May 6 10:43 ..
295+
dr-xr-xr-x 5 ftp ftp 4096 May 6 10:43 CentOS
296+
dr-xr-xr-x 3 ftp ftp 18 Jul 10 2008 Fedora
278297

279-
(Contributed by Tarek Ziadé and Giampaolo Rodolà; :issue:`4972`.)
298+
Other file-like objects such as :class:`mmap.mmap` and :func:`fileinput.input`
299+
also grew auto-closing context managers::
280300

281-
* A warning message will now get printed at interpreter shutdown if the
282-
:data:`gc.garbage` list isn't empty. This is meant to make the programmer
283-
aware that their code contains object finalization issues.
301+
with fileinput.input(files=('log1.txt', 'log2.txt')) as f:
302+
for line in f:
303+
process(line)
284304

285-
(Added by Antoine Pitrou; :issue:`477863`.)
305+
(Contributed by Tarek Ziadé and Giampaolo Rodolà in :issue:`4972`, and
306+
by Georg Brandl in :issue:`8046` and :issue:`1286`.)
286307

287308
* The :mod:`os` module now has the :const:`ST_RDONLY` and :const:`ST_NOSUID`
288309
constants, for use with the :func:`~os.statvfs` function.
@@ -395,15 +416,39 @@ Multi-threading
395416
argument. (Contributed by Torsten Landschoff; :issue:`850728`.)
396417

397418

398-
.. Optimizations
399-
=============
419+
Optimizations
420+
=============
400421

401-
Major performance enhancements have been added:
422+
A number of small performance enhancements have been added:
402423

403-
* Stub
424+
* JSON decoding performance is improved and memory consumption is reduced
425+
whenever the same string is repeated for multiple keys.
426+
427+
(Contributed by Antoine Pitrou; :issue:`7451`.)
428+
429+
- Python's peephole optimizer now recognizes patterns such ``x in {1, 2, 3}`` as
430+
being a test for membership in a set of constants. The optimizer recasts the
431+
:class:`set` as a :class:`frozenset` and stores the pre-built constant.
432+
433+
Now that the speed penalty is gone, it is practical to start writing
434+
membership tests using set-notation. This style is both semantically clear
435+
and operationally fast::
436+
437+
extension = name.rpartition('.')[2]
438+
if extension in {'xml', 'html', 'xhtml', 'css'}:
439+
handle(name)
440+
441+
(Patch and additional tests by Dave Malcolm; :issue:`6690`).
442+
443+
* The fast-search algorithm in stringlib is now used by the :meth:`split`,
444+
:meth:`rsplit`, :meth:`splitlines` and :meth:`replace` methods on
445+
:class:`bytes`, :class:`bytearray` and :class:`str` objects. Likewise, the
446+
algorithm is also used by :meth:`rfind`, :meth:`rindex`, :meth:`rsplit` and
447+
:meth:`rpartition`.
404448

449+
(Patch by Florent Xicluna in :issue:`7622` and :issue:`7462`.)
405450

406-
Filenames and unicode
451+
Filenames and Unicode
407452
=====================
408453

409454
The filesystem encoding can be specified by setting the

0 commit comments

Comments
 (0)