3 ms·
Sure :) but it would require a deep change in Python language semantics, without which this isn't possible. You'd have to carry that information in the AST som
by nothrabannosir 8y ago
Sure :) but it would require a deep change in Python language semantics, without which this isn't possible.
You'd have to carry that information in the AST somehow. From a call site, a function object is just a an object with certain properties. "Did it have a return or not?" is not information which exists on that object. Only the return value is (when you call it), and if it is None, you don't know if that came from "return None" or from the default behaviour.
Python could enrich the function object to include that information, and it would essentially be "supporting 0 or 1 return values", instead of "n return values". But adding that no-assignment rule would be backwards incompatible. At that point, might as well go all the way and support any number return values :)