LionHeart123 / pyscripter

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

Code completion sucks in Python because of undeclared variables (Request) #668

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Edit code in PyScripter
2.  Assign a variable the result of a function call, such as:
       val = raw_input()
3.  Even though val will always be a string after this call, PyScripter does 
not provide code completion support because in Python, a function _could_ 
return *anything*...

What is the expected output? What do you see instead?
   I would like better code completion... it seems like in the cases where I most need it, it doesn't work.

What version of the product are you using? On what operating system?
2.5.3.0 (x86) on Windows 7.

Please provide any additional information below.

   This is an inherent flaw (not feature, IMO) with Python... and it would be difficult to improve using Python syntax only.  However, 99% of the time when I use a variable name I will only ever access it with a single known type.  There is just no way to communicate or enforce this in Python.
   But it would be nice if PyScripter could somehow get around it with some simple "hint" comments on the first use of a variable in a scope...  such as:
    val = None#type string
or maybe even:
    val = ''#type
since '' allready communicates the type.  Then PyScripter could always assume 
than the variable is type string and provide code completion help.

Original issue reported on code.google.com by AgentFri...@gmail.com on 5 Jul 2012 at 5:54

GoogleCodeExporter commented 9 years ago
I think this already exists, if you do the following code for example:
val = ''
val = foo()

val.<CODE COMPLETE WORKS HERE>

... then the code complete knows val is a string.

Perhaps I'm misunderstanding your issue?

Original comment by Chris.W....@gmail.com on 5 Jul 2012 at 10:41

GoogleCodeExporter commented 9 years ago
OK, I'm learning...  I was unable to get code completion for a number of types, 
such as string.  I'm not sure exactly why that was happening, but it seems to 
be working now.

SOME CLARIFICATIONS:

There are still two primary situations where PyScripter's code completion 
breaks down:  
  1. function parameters
  2. accessing attributes of a returned value

In the first case, assignig something to a parameter wipes it out, so is not an 
option.

   def delfind( str, sub):
      str = '' #oops, bad idea
      pos = str.find( sub)
              #^ no code completion help
      if pos >= 0:
         return str[:pos]+str[pos+len(sub):]
      else
         return str

   a= delfind('hi      bye').strip()
                          # ^no help here either

Don't know the best solution, but there's gotta be SOMETHING.

Original comment by AgentFri...@gmail.com on 7 Jul 2012 at 12:25

GoogleCodeExporter commented 9 years ago
Please read 
https://groups.google.com/forum/?fromgroups#!searchin/pyscripter/Code$20completi
on/pyscripter/TadjX_PO4fo/EXAcsqHZNS0J  for explanation of code completion in 
PyScripter.

Also http://pyscripter.blogspot.gr/2010/10/code-completion-delight.html and 
other blog posts about code completion.

Original comment by pyscripter on 11 Jul 2012 at 5:12

GoogleCodeExporter commented 9 years ago

Original comment by pyscripter on 11 Jul 2012 at 5:13

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
HERE IS A WORKAROUND for function parameters, which I've found quite helpful... 

def myfunc( param1, param2):
    if 0:
        param1 = ''
        param2 = SomeClass()

    param2.   ...

Now if only it could be done w/ out adding dead code.

Original comment by AgentFri...@gmail.com on 13 Jul 2012 at 8:52