Author Topic: autolist problem in Python  (Read 258 times)

rowbearto

  • Senior Community Member
  • Posts: 1672
  • Hero Points: 119
autolist problem in Python
« on: January 28, 2020, 03:28:31 am »
See the "========== LOOK HERE ============" in below Python sample.

In a different Python IDE, when I press the "." (dot), that IDE's autolist presents me "field1" and "field2" as it recognizes that funcThatReturnsSampleClass() returns an instance of SampleClass.

But SlickEdit is not giving any autolist, no opportunity to easily obtain "field1" or "field2".

Not sure if this is a bug report or a feature request.

Code: [Select]
#!/usr/bin/python3

class SampleClass(object):
    def __init__(self):
        self.field1 = "abc"
        self.field2 = "def"

def funcThatReturnsSampleClass():
    return SampleClass()

def funcThatUsesSampleClass():
    sampleClassInstance = funcThatReturnsSampleClass()

    # ========== LOOK HERE ============
    # After typing the "." (dot) after sampleClassInstance below, autolist should present
    # "field1" and "field2", but it doesn't
    fieldToPrint = sampleClassInstance.

    print("sampleClassInstance.field1: {}".format(fieldToPrint))

funcThatUsesSampleClass()

Dennis

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2969
  • Hero Points: 440
Re: autolist problem in Python
« Reply #1 on: January 28, 2020, 03:38:39 pm »
That would be a feature request, and a rather sophisticated one at this, because we would have to deduce the return type of "funcThatReturnsSampleClass()" from the type of the expression in it's return statement, which is kind of easy for that function, but some Python functions are slightly more complicated.  You could have multiple returns with different expressions returning types in different branches of the type hierarchy, the parser is in no position to deduce the least common denominator within a class hierarchy.

Another option, that we already had a feature request filed for, is for SlickEdit to handle Python 3 function type hints.

rowbearto

  • Senior Community Member
  • Posts: 1672
  • Hero Points: 119
Re: autolist problem in Python
« Reply #2 on: January 28, 2020, 03:42:08 pm »
Most of the time functions only return 1 type (or None) so in the case where only 1 is returned, which happens a large majority of the time, this could be tremendously helpful.

As I said a competitor IDE is doing it so I think SE should keep up with competitors.

Handling type hints would also be helpful, but I can't guarantee that they are always there as they are optional.