ipython: Tab complete of args list runs unexpected property code
Ipython executes parts of my code when using the autocomplete functionality.
System info:
>> python -c "import IPython; print(IPython.sys_info())"
{'commit_hash': u'8b97549',
'commit_source': 'repository',
'default_encoding': 'UTF-8',
'ipython_path': '/home/ipython/IPython',
'ipython_version': '4.1.0-dev',
'os_name': 'posix',
'platform': 'Linux-3.16.0-53-generic-x86_64-with-Ubuntu-14.04-trusty',
'sys_executable': '/home/ipython/virtual_environment/bin/python',
'sys_platform': 'linux2',
'sys_version': '2.7.6 (default, Jun 22 2015, 17:58:13) \n[GCC 4.8.2]'}
Example:
In [1]: class Hello(object):
@property
def hello(self):
print "It's me"
In [2]: h=Hello()
Trying to autocomplete h.b
, h.hello
or h.b(
works as I would expect. However h.h(
or h.hello(
results in
In [3]: h.h(It's me
Display all ... possibilities? (y or n)
....
In [3]: h.h(
which resulted in an unexpected printout.
About this issue
- Original URL
- State: open
- Created 9 years ago
- Reactions: 2
- Comments: 16 (3 by maintainers)
Curiously, this also happens with plain Python. I just reproduced this in a fresh minimal conda environment with only Python 3.9, and see that it is in fact executing on autocompletion of
h.<TAB>
, but there is no IPython nor Jedi around:I searched for an issue in the Python bug tracker, but could not find anything.
Also, please allow me one remark on this:
At least for our part (and probably also @natezb), this is not primarily about speed, but undesirable communication/code execution (in this case communication with hardware over the wire).
Properties are used to implement a simple (for the user) instrument interaction API, e.g. both setting and getting e.g. an
instrument.voltage
, while hiding away all the communication, value validation, and other details.I sometimes use a sourcemeter instrument (think of it as a complicated power supply plus multimeter) with ~35 properties defined. Depending on the instrument state/configuration, not all are appropriate to run/query. I’ll have to check some time what exactly happens if I try to autocomplete on that one (see another demonstration in another package here). Yes, that could well become a speed issue on a serial connection, but I am more concerned about accidental side effects of code that was never intentionally run by the user, when all they wanted was to know what is available.
I am still seeing this issue with Jedi 0.15.1