title: PyCharm TensorFlow warning - Type 'Variable' doesn't have expected attribute '__sub__'
body: <p>Upon copying retrain.py from the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/image_retraining/retrain.py" rel="nofollow noreferrer">TensorFlow GitHub repository</a></p>
  <p>And then opening it in <code>PyCharm</code>, on lines 794 and 802 <code>PyCharm</code> shows the following warning:</p>
  <pre><code>Type 'Variable' doesn't have expected attribute '__sub__'
  </code></pre>
  <p>Here is a screenshot if that helps:</p>
  <p><a href="https://i.stack.imgur.com/R2FWr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R2FWr.png" alt="enter image description here" /></a></p>
  <p>Can somebody please explain:</p>
  <ol>
  <li><p>What does this mean?</p>
  </li>
  <li><p>How can this be resolved or the warning suppressed?</p>
  </li>
  </ol>
  <p>Clearly PyCharm thinks that <code>layer_weights</code> does not have an attribute <code>&quot;__sub__&quot;</code>, but what does this mean and why would a <code>__sub__</code> attribute be necessary?  The function <code>variable_summaries()</code> does not refer to an attribute <code>__sub__</code> (copied/pasted starting at line 735):</p>
  <pre><code>def variable_summaries(var):
      &quot;&quot;&quot;Attach a lot of summaries to a Tensor (for TensorBoard visualization).&quot;&quot;&quot;
      with tf.name_scope('summaries'):
          mean = tf.reduce_mean(var)
          tf.summary.scalar('mean', mean)
          with tf.name_scope('stddev'):
              stddev = tf.sqrt(tf.reduce_mean(tf.square(var - mean)))
          tf.summary.scalar('stddev', stddev)
          tf.summary.scalar('max', tf.reduce_max(var))
          tf.summary.scalar('min', tf.reduce_min(var))
          tf.summary.histogram('histogram', var)
  # end of function
  </code></pre>
  <p>Can somebody explain why an attribute <code>__sub__</code> would be necessary?</p>
  <p>After reading the <a href="https://stackoverflow.com/questions/6318814/how-can-i-tell-pycharm-what-type-a-parameter-is-expected-to-be">this</a> post, I'm under the impression that a comment to suppress this warning could be added, possibly something like:</p>
  <pre><code>@type whatGoesHere: ??
  @attribute __sub__: comment here??    # is this correct?
  @param whatGoesHere: ??
  </code></pre>
  <p>Is something like this doable, and what should the comment be?</p>
  <p>I prefer to not disable PyCharm's warnings as I find them helpful in many cases.  Can somebody please provide some enlightenment on the above so as to avoid disabling this warning in PyCharm?</p>
  <p><strong>- Edit:</strong></p>
  <p>Thanks for the explanation Shu.  For the moment this seems to be the best way to deal with this in PyCharm without disabling that inspection entirely:</p>
  <pre><code># this comment is necessary to suppress an unnecessary PyCharm warning
  # noinspection PyTypeChecker
  variable_summaries(layer_weights)
  </code></pre>
  <p>If eventually somebody could inform me of a better option that would be great.</p>