title: MyPy - how do you actually use typeshed stubs in annotations?
body: <p>Note: <a href="https://stackoverflow.com/a/38934841/8378419">this answer on SO</a> does NOT answer my question. It merely restates what I already have read.</p>
  
  <p>How is this supposed to work? Everything I read says <code>typeshed</code> is bundled with <code>MyPy</code> and contains stubs for third party libraries. I have <code>MyPy</code> installed and running in a virtualenv and I'm trying to use it to type <code>Flask</code> code but I'm just not getting it.</p>
  
  <p>I have a background in TypeScript, and I was looking for something similar but I don't understand how we are supposed to use stubs with <code>MyPy</code>. For example, I have this function:</p>
  
  <pre><code>def create_app(config_name="default"):
      app: Flask = Flask(__name__)
      app.config.from_object(Configuration)
      CORS(app)
      register_extensions(app)
      register_blueprints(app)
  
      @app.route("/health")
      def health_check():
          return json.dumps({"status": "up"})
  
      return app
  </code></pre>
  
  <p>Pretty standard for Flask, but with strict disallow any settings this becomes an unsalvageable mess. What is the type of app? I know that <code>typeshed</code> <a href="https://github.com/python/typeshed/tree/master/third_party/2and3/flask" rel="noreferrer">has stubs for flask</a> but I cannot figure out how to actually utilize those stubs. The <code>typeshed</code> docs say:</p>
  
  <blockquote>
    <p>If you're just using mypy (or pytype or PyCharm), as opposed to developing it, you don't need to interact with the typeshed repo at all: a copy of typeshed is bundled with mypy.</p>
  </blockquote>
  
  <p>So I'm assuming I do not need to import the types, the docs don't make any mention of importing them anyway.</p>
  
  <p>For example, there is a stub called <code>app.pyi</code> but if I annotate the function like this:</p>
  
  <pre><code>def create_app(config_name="default") -&gt; app:
  </code></pre>
  
  <p>I get the error <code>name app is not defined</code>. If I import it:</p>
  
  <pre><code>from typeshed import app
  </code></pre>
  
  <p>I get the error <code>Return type becomes any due to an unfollowed import</code> which, as far as I can tell, means there is no such module <code>typeshed</code> or it has no member called <code>app</code>.</p>
  
  <p>So how do I actually get access to these <code>typeshed</code> stubs? My last resort is to simply clone the <code>typeshed</code> repo and point <code>mypy</code> to it as a custom typeshed dir, but I'd really like to do things the proper way.</p>