Neil Schemenauer wrote:
> The := would assign but not declare a variable
> in the current scope.
There are other benefits to such a statement, too, since we can make it
similar to other augmented assignments by letting the object being assigned to
interfere with the process.
a := 2
could translate to something like:
a = a.__assign__(2)
with the default behaviour of __assign__ simply being:
def __assign__(rhs)
return rhs
This gives you:
- runtime checking for typos (you can't accidentally declare a new variable
with := when you really meant to assign to an existing one)
- if/when control flow analysis is added to the AST compiler, it will be
picked up as an error at compile time along with the other augmented assignments
- the object being assigned to can validate/modify its replacement (e.g.
automatically wrapping it in a weakref proxy, or checking that it has the
correct type)
Cheers,
Nick.
--
Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com