title: What is the difference between "cast(...)" and "... # type: ..."?
body: <p>When type-hinting in Python I have two options for marking an expression as certain type:</p>
  
  <pre><code>from typing import cast
  
  foo = cast(str, expression)
  bar = expression  # type: str
  </code></pre>
  
  <p>What's the difference between the two?</p>
  
  <p>I have the impression that sometimes using <code>cast</code> works, while sometimes I have to use the comment. But I have not yet figured out a pattern. Unfortunately I currently have no code-example at hand where one works but not the other.</p>