tab-complete can mutate objects!
See original GitHub issueConsider the class.
class X:
T_cnt = []
@property
def T(self):
self.T_cnt.append(len(self.T_cnt))
Thus X.T_cnt
keeps track of the number of times that X().T
was called.
The following demonstrates the bug:
>>> x = X()
>>> x.<tab>
>>> x.<tab>
>>> X.T_cnt
[0, 1]
Each time I use <tab> to bring up the list of attributes of x
, x.T
is called under the hood. This occurs in both the ipython console and Jupyter notebook.
I am using iPython 6.1.0
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Spigot Plugin Development - Tab Completion with Commands
Tab completion is when suggestions come up in the minecraft chat for the next argument for the command. We can do this by...
Read more >XRef: Tab-to-autocomplete in IPython + Python3 results in Spark job ...
XRef: Tab-to-autocomplete in IPython + Python3 results in Spark job execution # ... I've found the line that does that. ... tab-complete can...
Read more >Washing your code: avoid mutation - Artem Sapegin
Mutations happen when we change a JavaScript object or array ... Mutations make code harder to understand and can lead to hard-to-find bugs....
Read more >Class object tab completion & improper field names
Tab completions and property access can be customized for user-created Matlab ... Class object tab completion & improper field names.
Read more >Integrating your objects with IPython
To change the attributes displayed by tab-completing your object, define a __dir__(self) method ... IPython can display richer representations of objects.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
It’s hard to do any useful introspection if we guarantee that tab completion has no side effects, because Python allows objects to override so much of their behaviour: almost anything we do might have side effects.
So we’ve generally tried to ensure that tab completion doesn’t do things which are likely to have side effects (like calling regular methods), but allowed it to do things which usually don’t (like attribute access).
I generally consider it bad design for property getters to have non-trivial side effects, because it’s surprising both for introspection software and developers when that happens on attribute access.
I’ll have a look, but not soon. With PyBay comming and JupyterCon just after it is tough.
It’s on my todo list though.
On Mon, Jul 31, 2017 at 7:28 AM, Thomas Kluyver notifications@github.com wrote: