You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Update ast_interactivity for more complex assignments. #10633
#10598 added the possibility to change the ast-interactivity mode for the last assignment of cells.
Though it work only for simple variable assignments.
Should we try to do that for more complex ones like a[0].b = something_else() , probably by copying the LHS of the assignment ?
It's possible, and not that unusual, for something like a.foo to be a property which calls code on access. That's not necessarily a problem for an opt-in feature, but we should keep it in mind.
Hello. Would really be useful if this could be done. Basically we only want the value of the evaluated RHS before assignment, irrespective of the target of the assignment.
As @takluyver says tt may be transformed to something else by property setters, that's understood and for getting that we should use the relevant getter only. But whatever is passed to the setter we would like to see that's all.
The way the simple version works is that a cell ending in x = something() implicitly gets a bare x afterwards. Showing the value produced before the assignment gets a bit more complicated. You could read back the target and live with the possibility that it does something different, or triggers side effects:
a.b=something()
a.b
You can't just evaluate the RHS again, because it can produce something different:
a.b=next(iterator)
next(iterator) # Oops
In theory, the best approach is to modify the code to something like this:
_tmp=something()
a.b=_tmp_tmp
But that would be more complex than just sticking something on the end - you probably want to make sure the temporary variable name isn't already used, and delete the variable afterwards to avoid an unwanted reference.
Activity
takluyver commentedon Jun 2, 2017
It's possible, and not that unusual, for something like
a.footo be a property which calls code on access. That's not necessarily a problem for an opt-in feature, but we should keep it in mind.jamadagni commentedon Dec 12, 2024
Hello. Would really be useful if this could be done. Basically we only want the value of the evaluated RHS before assignment, irrespective of the target of the assignment.
As @takluyver says tt may be transformed to something else by property setters, that's understood and for getting that we should use the relevant getter only. But whatever is passed to the setter we would like to see that's all.
Thanks!
takluyver commentedon Jan 6, 2025
The way the simple version works is that a cell ending in
x = something()implicitly gets a barexafterwards. Showing the value produced before the assignment gets a bit more complicated. You could read back the target and live with the possibility that it does something different, or triggers side effects:You can't just evaluate the RHS again, because it can produce something different:
In theory, the best approach is to modify the code to something like this:
But that would be more complex than just sticking something on the end - you probably want to make sure the temporary variable name isn't already used, and delete the variable afterwards to avoid an unwanted reference.
Carreau commentedon Jan 6, 2025
as we rewrite ast, we can use variable names that are invalid python identifiers.