Python 3.6.2 released

Second maintenance release with many new features and optimizations
24 July 2017   539
Python

Multi-paradigm programming language with easy-to-use syntax and many features including the support of the object-oriented and structured programming.

Great news for all Python developers. Python 3.6.2 is now available.

Python 3.6.2 is the second maintenance release of Python 3.6, which was initially released in 2016-12 to great interest. With the release of 3.6.2, developers provide the second set of bugfixes and documentation updates to 3.6. The next maintenance release is expected to follow in about 3 months, around the end of 2017-09. Let's see what's inside.

Major new features of the 3.6 series, compared to 3.5

Among the new major new features in Python 3.6 are:

  • PEP 468, Preserving Keyword Argument Order
  • PEP 487, Simpler customization of class creation
  • PEP 495, Local Time Disambiguation
  • PEP 498, Literal String Formatting
  • PEP 506, Adding A Secrets Module To The Standard Library
  • PEP 509, Add a private version to dict
  • PEP 515, Underscores in Numeric Literals
  • PEP 519, Adding a file system path protocol
  • PEP 520, Preserving Class Attribute Definition Order
  • PEP 523, Adding a frame evaluation API to CPython
  • PEP 524, Make os.urandom() blocking on Linux (during system startup)
  • PEP 525, Asynchronous Generators (provisional)
  • PEP 526, Syntax for Variable Annotations (provisional)
  • PEP 528, Change Windows console encoding to UTF-8
  • PEP 529, Change Windows filesystem encoding to UTF-8
  • PEP 530, Asynchronous Comprehensions

New library modules:

  • secrets: PEP 506 – Adding A Secrets Module To The Standard Library.

 CPython implementation improvements:

  • The dict type has been reimplemented to use a more compact representation based on a proposal by Raymond Hettinger and similar to the PyPy dict implementation. This resulted in dictionaries using 20% to 25% less memory when compared to Python 3.5.
  • Customization of class creation has been simplified with the new protocol.
  • The class attribute definition order is now preserved.
  • The order of elements in **kwargs now corresponds to the order in which keyword arguments were passed to the function.
  • DTrace and SystemTap probing support has been added.
  • The new PYTHONMALLOC environment variable can now be used to debug the interpreter memory allocation and access errors.

Significant improvements in the standard library:

  • The asyncio module has received new features, significant usability and performance improvements, and a fair amount of bug fixes. Starting with Python 3.6 the asyncio module is no longer provisional and its API is considered stable.
  • A new file system path protocol has been implemented to support path-like objects. All standard library functions operating on paths have been updated to work with the new protocol.
  • The datetime module has gained support for Local Time Disambiguation.
  • The typing module received a number of improvements.
  • The tracemalloc module has been significantly reworked and is now used to provide better output for ResourceWarning as well as provide better diagnostics for memory allocation errors.

Security improvements:

  • The new secrets module has been added to simplify the generation of cryptographically strong pseudo-random numbers suitable for managing secrets such as account authentication, tokens, and similar.
  • On Linux, os.urandom() now blocks until the system urandom entropy pool is initialized to increase the security. See the PEP 524 for the rationale.
  • The hashlib and ssl modules now support OpenSSL 1.1.0.
  • The default settings and feature set of the ssl module have been improved.
  • The hashlib module received support for the BLAKE2, SHA-3 and SHAKE hash algorithms and the scrypt() key derivation function.

Windows improvements:

  • PEP 528 and PEP 529, Windows filesystem and console encoding changed to UTF-8.
  • The py.exe launcher, when used interactively, no longer prefers Python 2 over Python 3 when the user doesn’t specify a version (via command line arguments or a config file). Handling of shebang lines remains unchanged - “python” refers to Python 2 in that case.
  • python.exe and pythonw.exe have been marked as long-path aware, which means that the 260 character path limit may no longer apply.
  • ._pth file can be added to force isolated mode and fully specify all search paths to avoid registry and environment lookup.
  • python36.zip file now works as a landmark to infer PYTHONHOME.

Related links

What is YAPF?

A formatter for Python files, developed by Google team
30 October 2017   439

What is YAPF?

Most of the current formatters for Python --- e.g., autopep8, and pep8ify --- are made to remove lint errors from code. This has some obvious limitations. For instance, code that conforms to the PEP 8 guidelines may not be reformatted. But it doesn't mean that the code looks good.

YAPF takes a different approach. It's based off of 'clang-format', developed by Daniel Jasper. In essence, the algorithm takes the code and reformats it to the best formatting that conforms to the style guide, even if the original code didn't violate the style guide. The idea is also similar to the 'gofmt' tool for the Go programming language: end all holy wars about formatting - if the whole codebase of a project is simply piped through YAPF whenever modifications are made, the style remains consistent throughout the project and there's no point arguing about style in every code review.

The ultimate goal is that the code YAPF produces is as good as the code that a programmer would write if they were following the style guide. It takes away some of the drudgery of maintaining your code.

Code examples

YAPF takes this code:

x = {  'a':37,'b':42,

'c':927}

y = 'hello ''world'
z = 'hello '+'world'
a = 'hello {}'.format('world')
class foo  (     object  ):
  def f    (self   ):
    return       37*-+2
  def g(self, x,y=42):
      return y
def f  (   a ) :
  return      37+-+a[42-x :  y**3]

and reformat it into:

x = {'a': 37, 'b': 42, 'c': 927}

y = 'hello ' 'world'
z = 'hello ' + 'world'
a = 'hello {}'.format('world')


class foo(object):
    def f(self):
        return 37 * -+2

    def g(self, x, y=42):
        return y


def f(a):
    return 37 + -+a[42 - x:y**3]

See GitHub for more information.