[Python-Dev] The new and improved PEP 572, same great taste with 75% less complexity! (original) (raw)

Mikhail V mikhailwas at gmail.com
Thu Apr 26 21:33:43 EDT 2018


On Thu, Apr 26, 2018 at 4:27 PM, Kirill Balunov <kirillbalunov at gmail.com> wrote:

2018-04-24 18:31 GMT+03:00 Chris Angelico <rosuav at gmail.com>:

Not sure, but if additional motivating examples are required, there is a common pattern for dynamic attribute lookup (snippet from copy.py): reductor = dispatchtable.get(cls) if reductor: rv = reductor(x) else: reductor = getattr(x, "reduceex", None) if reductor: rv = reductor(4) else: reductor = getattr(x, "reduce", None) if reductor: rv = reductor() else: raise Error("un(shallow)copyable object of type %s" % cls) which can with the current binding expression syntax simplified to: if reductor := dispatchtable.get(cls): rv = reductor(x) elif reductor := getattr(x, "reduceex", None): rv = reductor(4) elif reductor := getattr(x, "reduce", None): rv = reductor() else: raise Error("un(shallow)copyable object of type %s" % cls)

To me this looks more like a motivating example for adding GOTO statement to Python... Anybody writing a PEP? :) And should not the above be wrapped in a function? (a workaround in abscence of GOTO)

Also, the ELIF is merely an edge case: once you have something like:

if value : rv = f(x) else : temp = ... value = f1(temp) print (value) if value : rv = f2(x) ...

then it does not wrap into anything anymore.

Mikhail



More information about the Python-Dev mailing list