thecocce / pyscripter

Automatically exported from code.google.com/p/pyscripter
0 stars 0 forks source link

PyScripter alters content of mutable objects when I type the dot '.' #422

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

From the Python interpreter, create this function:

>>> def myfunc(some_list):
>>>     some_list.append(2)
>>>     return some_list

Now create an empty list 'abc' and type "myfunc(abc)." to invoke the method 
help list. Without hitting enter, erase the line. 'abc' will now contain the 
number 2.

What is the expected output? What do you see instead?

    I expect 'abc' to not change when I don't run any commands. Instead, the variable's contents are modified.

What version of the product are you using? On what operating system?

    PyScripter 2.1.1.0, WinXP

Please provide any additional information below.

Original issue reported on code.google.com by andrew.r...@gmail.com on 24 Sep 2010 at 3:33

GoogleCodeExporter commented 9 years ago
Autocompletion in the interpreter involves the evaluation of the expression on 
the left of the dot.  There is no other way to provide accurate 
auto-completion.  In your example the expression has a side effect, hence the 
outcome.  

The alternative is to not provide autocompletion in the case of function calls. 
 Is this preferable?

Original comment by pyscripter on 24 Sep 2010 at 9:19

GoogleCodeExporter commented 9 years ago
> The alternative is to not provide autocompletion
> in the case of function calls.  Is this preferable?

Yes, this is preferable (even though autocomplete is a cool and useful thing).  
Evaluating a function when the user does not expect the function to be run can 
do unwanted/unexpected things.  Thus, autocompletion should be implemented so 
that it does not cause a state change in the Python workspace.

I checked one of the other mature IDE's and they do not provide autocompletion 
when a function is involved...I assume for the same reason being discussed 
here.  

Original comment by andrew.r...@gmail.com on 24 Sep 2010 at 10:16

GoogleCodeExporter commented 9 years ago
Fixed in version control.

No code completion over brackets.
I could still provide code completion for 
a[10].
or 
(1+1).
but it is going to be hard to tell whether a function call is inside the 
brackets.

So from now on code completion is only provided for

somevar.attribute.attribute.

It is a pity but I accept your argument about the risk involved.

Original comment by pyscripter on 25 Sep 2010 at 12:19

GoogleCodeExporter commented 9 years ago

Original comment by pyscripter on 25 Sep 2010 at 12:22

GoogleCodeExporter commented 9 years ago
For brackets, you could take what's inside and ask Python if it's an integer.  
So:

i=1
s[i].

would allow autocompletion to work.

Original comment by andrew.r...@gmail.com on 25 Sep 2010 at 2:16

GoogleCodeExporter commented 9 years ago
Is not as simple.  First of all indices do not have to be integer.  Second one 
needs to consider things like

a[f(g(x))] etc.

Original comment by pyscripter on 25 Sep 2010 at 4:16

GoogleCodeExporter commented 9 years ago
> First of all indices do not have to be integer.

This is true. I'm saying you could take what's in the brackets and ask Python 
if it's an integer. If it is, then grab its value and invoke autocompletion.  
If it isn't, skip autocompletion.

I did this in an app I created that uses autocompletion and it works well:

s[i].  gives autocompletion because Python says 'i' is in integer object, and
s[f(x)]. skips autocompletion because the Python says 'f' is not an integer 
object.

I use PyInt_Check(PyObject *o) to do type checking.

Original comment by andrew.r...@gmail.com on 25 Sep 2010 at 4:40

GoogleCodeExporter commented 9 years ago
OK.  It now handles square brackets if the expression inside does not contain 
parenthesis.

e.g.
mylist[a+b].

Original comment by pyscripter on 25 Sep 2010 at 11:05

GoogleCodeExporter commented 9 years ago
Awesome, thanks!

Original comment by andrew.r...@gmail.com on 26 Sep 2010 at 3:33