Python-ideas summary [2018-08]

PEP 505: None-aware operators

The discussion the previous month about PEP 505 None-aware operators continues (second thread).

With expressions

Ken Hilton suggests that an expression version of the with statement would be useful. For example:

contents = f.read() with open('file') as f #the most obvious one
multiplecontents = [f.read() with open(name) as f for name in names] #reading multiple files

The rejected PEP 463 (Exception-catching expressions) is mentioned.

Revisiting dedicated overloadable boolean operators

Todd suggests new operators and corresponding dunder methods for boolean and, or, not, and xor, so that projects that need custom behavior from these (e.g. numpy or sqlalchemy) need not abuse the existing bitwise operators. A discussion about allowing custom infix operators develops.

Syntactic sugar to declare partial functions

Fabrizio Messina proproses using curly braces as syntactic sugar for declaring partial functions.

Robert Vanden Eynde suggests using funcoperators (which is his project) for this.

Eventually the discussion descends into a less-than-polite argument about whether jargon is harmful. Some discussion follows about how to improve the quality of discourse, and eventually some more extensive discussion about the use of jargon, partciuarly centered on lambda.

Make "yield" inside a with statement a SyntaxError

Ken Hilton suggests that it is problematic to yield from inside a with statement, because then the with will stay open (e.g. leaving file handles open longer than expected).

Python docs page: In what ways is None special

Jonathan Fine announces a draft piece of documentation that introduces None.

Pre-conditions and post-conditions

Marko Ristin-Kaufmann suggests that python should better support design by contract, giving icontract as an example of a python implementation of the idea.

A GUI for beginners and experts alike

Mike Barnett suggests that his project PySimpleGUI should be made part of the standard library, leading to some discussion of existing python GUI options.

Unpacking iterables for augmented assignment

James Lu suggests that it should be possible to use augmented assignment with iterables:

a = 0
b = 0
a, b += 1, 2
# a is now 1
# b is now 2