Possible duplicate:
How can I tell PyCharm what type of parameter should be?
I found that Python coding in IntelliJ IDEA (and PyCharm), you can use Epytext or reStructuredText to document the expected parameter types and return types. They can be provided as needed to help the IDE provide autocomplete and improve validation error checking.
I cannot figure out how to specify type annotations for instance variables and class variables. Is there a way to do this as IntelliJ recognizes?
For example, let's say IntelliJ cannot infer the return type of some_function() , and the function is in the library, where we cannot add the @rtype comment. How can I specify the type of an instance variable self.bar ?
class Foo: def __init__(self):
Edit:
Finally, I found the correct syntax for documenting instance variable types. Place the docstring immediately after assigning the variable.
class Foo: def __init__(self): self.bar = some_function() """@type: Bar"""
It should be noted that IntelliJ / PyCharm only understands the format of the docstring variable . The docstring format of a comment or type specification in a docstring class does not work.
Also, there it turns out to be an error where docstrings variables do not work for double underscore prefix variables.
source share