What’s New In Python 3.5
| Release: | 3.5.0a0 |
| Date: | July 03, 2014 |
This article explains the new features in Python 3.5, compared to 3.4.
For full details, see the Misc/NEWS file.
Note
Prerelease users should be aware that this document is currently in
draft form. It will be updated substantially as Python 3.5 moves towards
release, so it’s worth checking back even after reading earlier versions.
Summary – Release highlights
New syntax features:
New library modules:
New built-in features:
Implementation improvements:
- When the LC_TYPE locale is the POSIX locale (C locale),
sys.stdin and sys.stdout are now using the
surrogateescape error handler, instead of the strict error handler
(issue 19977).
Significantly Improved Library Modules:
Security improvements:
Please read on for a comprehensive list of user-facing changes.
Other Language Changes
Some smaller changes made to the core Python language are:
Improved Modules
os
- os.stat_result now has a st_file_attributes field on Windows,
containing the dwFileAttributes member of the
BY_HANDLE_FILE_INFORMATION structure returned by
GetFileInformationByHandle() (contributed by Ben Hoyt in
issue 21719).
shutil
- move() now accepts a copy_function argument, allowing,
for example, copy() to be used instead of the default
copy2() if there is a need to ignore metadata. (Contributed by
Claudiu Popa in issue 19840.)
signal
- Different constants of signal module are now enumeration values using
the enum module. This allows meaningful names to be printed during
debugging, instead of integer “magic numbers”. (contributed by Giampaolo
Rodola’ in issue 21076)
smtpd
- Both SMTPServer and smtpd.SMTPChannel now accept a
decode_data keyword to determine if the DATA portion of the SMTP
transaction is decoded using the utf-8 codec or is instead provided to
process_message() as a byte string. The default
is True for backward compatibility reasons, but will change to False
in Python 3.6. (Contributed by Maciej Szulik in issue 19662.)
- It is now possible to provide, directly or via name resolution, IPv6
addresses in the SMTPServer constructor, and have it
successfully connect. (Contributed by Milan Oberkirch in issue 14758.)
smtplib
- A new auth() method provides a convenient way to
implement custom authentication mechanisms (contributed by Milan Oberkirch in
issue 15014).
Optimizations
The following performance enhancements have been added:
Build and C API Changes
Changes to Python’s build process and to the C API include:
Deprecated
Unsupported Operating Systems
Deprecated Python modules, functions and methods
- The formatter module has now graduated to full deprecation and is still
slated for removal in Python 3.6.
- smtpd has in the past always decoded the DATA portion of email
messages using the utf-8 codec. This can now be controlled by the new
decode_data keyword to SMTPServer. The default value is
True, but this default is deprecated. Specify the decode_data keyword
with an appropriate value to avoid the deprecation warning.
Deprecated functions and types of the C API
Porting to Python 3.5
This section lists previously described changes and other bugfixes
that may require changes to your code.
Changes in the Python API
- Before Python 3.5, a datetime.time object was considered to be false
if it represented midnight in UTC. This behavior was considered obscure and
error-prone and has been removed in Python 3.5. See issue 13936 for full
details.
- ssl.SSLSocket.send() now raises either ssl.SSLWantReadError
or ssl.SSLWantWriteError on a non-blocking socket if the operation
would block. Previously, it would return 0. See issue 20951.
- The __name__ attribute of generator is now set from the function name,
instead of being set from the code name. Use gen.gi_code.co_name to
retrieve the code name. Generators also have a new __qualname__
attribute, the qualified name, which is now used for the representation
of a generator (repr(gen)). See issue 21205.
Changes in the C API
- The PyMemAllocator structure was renamed to
PyMemAllocatorEx and a new calloc field was added.