On Wed, Feb 20, 2019 at 5:28 AM Grant Edwards <grant.b.edwa...@gmail.com> wrote:
>
> On 2019-02-19, Chris Angelico <ros...@gmail.com> wrote:
> > On Wed, Feb 20, 2019 at 3:23 AM Grant Edwards <grant.b.edwa...@gmail.com> 
> > wrote:
> >
> >> Those object _may_ each have different identies.  Is it required that
> >> they do?  If an assignment is done on name referring to an object with
> >> no other references, would it be allowed that the "old" object is
> >> destroyed and its ID reused for a new object being created by the RHS
> >> of the assignment?
> >>
> >> Admittedly, that would be a rather odd way to do things.  One would
> >> expect that first the RHS is evaluated (perhaps creating a new
> >> object), then the name is rebound.
> >
> > Correct, the RHS is evaluated first. So the old object is still
> > around (important for statements like "x = x.lower()").
>
> Not doing the unbinding until after the RHS evaluation is also
> important for preventing surprises due to exceptions raised while the
> RHS is evaluated.  One would reasonably expect that if that happens
> the original binding of the name on the LHS is unchanged.
>
> Dunno if that's actually specified anywhere...
>

It is, yes:

https://docs.python.org/3/reference/expressions.html#evaluation-order

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to