title: Mypy Cannot Find All Modules in Python3 Django App
body: <p><strong>Background</strong></p>
  
  <p>I work in a large Python3 repo that is type checked with Mypy. In accordance with <a href="https://www.python.org/dev/peps/pep-0420/" rel="nofollow noreferrer">PEP420</a> we do not use <code>__init__.py</code> files.</p>
  
  <p>Mypy recently added support for implicit namespace packages, but the implementation now follows the chain of <code>import</code> statements from a given entrypoint. In the case of this repo, (a Django app) there are many modules that are imported dynamically (like middleware) or not imported at all (tests and one-off scripts).</p>
  
  <p>Consider this example:</p>
  
  <pre><code>my-py3-repo/
  ├── hello/
  │   ├── services/
  │   │   └── hello_service.py
  │   └── hello.py
  ├── scripts/
  │   ├── db/
  │   │   └── migrate.py
  │   └── manage.py
  └── tests/
      └── hello/
          ├── services/
          │   └── hello_service_test.py
          └── hello_test.py
  </code></pre>
  
  <p>Assuming that <code>hello.py</code> imports <code>hello_service.py</code>, everything under the <code>hello</code> namespace will be type checked as expected with <code>mypy ./hello</code>.</p>
  
  <p><strong>Problem</strong></p>
  
  <p>However test discovery with <code>pytest</code>, <code>nose</code>, <code>django</code> et al works differently and <code>hello_test.py</code> would not usually import <code>hello_service_test.py</code>. There is currently no way for Mypy to discover <code>hello_service_test.py</code> with <code>mypy ./tests</code> (if not using <code>__init__.py</code>).</p>
  
  <p>Similarly, everything under the <code>scripts</code> directory would suffer the same problem.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I configure Mypy such that the <code>scripts</code> and <code>tests</code> directories are always type checked?</p>
  
  <p><strong>Configuration</strong></p>
  
  <pre class="lang-sh prettyprint-override"><code># Pipfile
  [dev-packages]
  mypy = "==0.670"
  [requires]
  python_version = "3.7"
  </code></pre>
  
  <pre class="lang-sh prettyprint-override"><code># setup.cfg
  [mypy]
  python_version = 3.7
  ignore_missing_imports = True
  namespace_packages = True
  </code></pre>
  
  <p>See also <a href="https://github.com/python/mypy/issues/6385" rel="nofollow noreferrer">this issue</a> I created in the Mypy repo.</p>