How to "inform" the editor from which class a parameter is (for completions purposes)
Hi,
I am defining a class, which receives another class object as a parameter in the __init__ stage.
example:
class a(object):
def __init__(b): #b is a class
a.att1 = b.att1
a.att2 = b.att2
a.att3 = b.att3
I would like to have completions for the 'b' class in the __init__ function. currently the editor does not suggest attribute when i start typing 'b.'.
Is there a way to "inform" the editor that b is an object of some class?
becuase for me, b is an object of a big class, which forces me to switch over to that class and search how its attributes are written in order to correctly use them with 'a' class objects.
Thanks!
I am defining a class, which receives another class object as a parameter in the __init__ stage.
example:
class a(object):
def __init__(b): #b is a class
a.att1 = b.att1
a.att2 = b.att2
a.att3 = b.att3
I would like to have completions for the 'b' class in the __init__ function. currently the editor does not suggest attribute when i start typing 'b.'.
Is there a way to "inform" the editor that b is an object of some class?
becuase for me, b is an object of a big class, which forces me to switch over to that class and search how its attributes are written in order to correctly use them with 'a' class objects.
Thanks!
Please sign in to leave a comment.
The type reference then is freeform text, so it can be hard to tell when you've got it set to something pycharm recognizes, but when you do, the Ctrl-Q (Quick Documentation) for that method should show b's "inferred type."
I thought there was a project setting somewhere to set to specify whether docstrings are in Restructured Text or epydoc, but I can't find it now.
def __init__(self, b:str):
However, this is not compatible with Python 2.7. For that version you have to add type information in docstrings.
You can verify if the syntax is correct, if the type is properly shown in the quick documentation popup (CTRL-Q on windows, CTRL-J on my Mac). There are a lot more options to annotate (return values, list of objects of a certain type, ...) For details see here: http://www.jetbrains.com/pycharm/webhelp/type-hinting-in-pycharm.html
You can also check "Collect run-time types information for code insight" in Preferences > Python debugger. For details see here: http://blog.jetbrains.com/pycharm/2013/02/dynamic-runtime-type-inference-in-pycharm-2-7/
Though it does raise a few others, i.e. what are "Generics" in Python?