diff --git a/pep-0572.rst b/pep-0572.rst index 64d03eeaf..5f1c6c82e 100644 --- a/pep-0572.rst +++ b/pep-0572.rst @@ -92,6 +92,25 @@ Some of these examples should be considered *bad code* and rejected by code review and/or linters; they are not, however, illegal. +Differences from regular assignment statements +---------------------------------------------- + +Using ``(EXPR as NAME)`` is similar to ``NAME = EXPR``, but has a number of +important distinctions. + +* Assignment is a statement; an SLNB is an expression whose value is the same + as the object bound to the new name. +* SLNBs disappear at the end of their enclosing statement, at which point the + name again refers to whatever it previously would have. SLNBs can thus + shadow other names without conflict (although deliberately doing so will + often be a sign of bad code). +* SLNBs cannot be closed over by nested functions, and are completely ignored + for this purpose. +* SLNBs do not appear in ``locals()`` or ``globals()``. +* An SLNB cannot be the target of any form of assignment, including augmented. + Attempting to do so will remove the SLNB and assign to the fully-scoped name. + + Example usage =============