Python Forum
iPython tab completion of method variable - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: iPython tab completion of method variable (/thread-2653.html)



iPython tab completion of method variable - sixteenornumber - Mar-31-2017

is there any way to get iPython to recognize the type of "each" in B.printBarList().  for example I want to use tab-complete in iPython so I type "each." but it doesn't know the type.  

# A.py
class A:
    
    def __init__(self):
        self._foo = "FOO"

    def getFoo(self):
        return self._foo
# B.py
from A import A
class B:

    def createBarList(self):
        '''create 10 instances of A in barList'''
        barList = []
        for i in range(10):
            barList.append(A())
        return barList

    def printBarList(self, barList):
        '''
        Itter over each A in barList and print each
        ***MY QUESTION*** the "each" in the loop below
        '''
        for each in barList:
            print(each.foo)

if __name__ == "__main__":

    b = b()
    barList = b.createBarList()
    b.printBarList()
Moderator Larz60+: Changed icode tags to Python tags (see help, BBCODE)


RE: iPython tab completion of method variable - sixteenornumber - Apr-04-2017

I found my answer.  as of python 3.5 


import typing

def foo(bar: int) --> int:
    return bar**2

in ipython when you enter,  "foo()" it wll prompt with "bar: int returns int". this also works with class types.

class Baz:
    def __init__(self):
        pass

def foo(bar: Baz) --> None:
    pass
Moderator Larz60+: Added Python tags. Please do this in the future (see help, BBCODE) second notice