title: How can I tell PyCharm/IDEA what type an instance or class variable is expected to be?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6318814/how-can-i-tell-pycharm-what-type-a-parameter-is-expected-to-be">How can I tell PyCharm what type a parameter is expected to be?</a>  </p>
  </blockquote>
  
  
  
  <p>I've discovered that coding Python in IntelliJ IDEA (and PyCharm), you can use Epytext or reStructuredText to document expected types of parameters and return types. These can be provided as-needed to help the IDE in providing autocompletion and improve its inspections error checking.</p>
  
  <p>What I can't quite figure out is how to specify type annotations for instance variables and class variables. Is there some way to do this in a way that IntelliJ will recognize?</p>
  
  <p>For example, say IntelliJ cannot infer the return type of <code>some_function()</code>, and the function is in a library where we cannot add a <code>@rtype</code> comment. How can I provide the type for the <code>self.bar</code> instance variable?</p>
  
  <pre><code>class Foo:
      def __init__(self):
          # How can I document that self.bar is of type Bar?
          self.bar = some_function()
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>Finally found the proper syntax for documenting the types of instance variables. Place a docstring directly after the variable assignment.</p>
  
  <pre><code>class Foo:
      def __init__(self):
          self.bar = some_function()
          """@type: Bar"""
  </code></pre>
  
  <p>Two things to note are that IntelliJ/PyCharm <a href="http://youtrack.jetbrains.com/issue/PY-7004" rel="nofollow noreferrer">only seems to understand the variable docstring format</a>. The comment docstring format, or specifying type in the class docstring does not work.</p>
  
  <p>Also, there <a href="http://youtrack.jetbrains.com/issue/PY-7003" rel="nofollow noreferrer">appears to be a bug</a> where variable docstrings don't work for double-underscore prefixed variables.</p>