Also, can I use namespace packages with mypy? If I...
# general
r
Also, can I use namespace packages with mypy? If I don't put
--namespace-packages
mypy doesn't find the imports, and if I put the option, mypy says my module was found twice (namespace_name.package_name.module and package_name.module).
I've updated my small repo https://github.com/Gaasmann/monorepants
./pants check ::
should show the issue
w
I think the issue is that you're missing an
__init__.py
src/turbocorp/___init___.py
seems to solve the problem
Used this mypy.ini as well
Copy code
[mypy]
namespace_packages = True

# Strictness
strict = True

# Error output
show_column_numbers = True
show_error_context = True
show_error_codes = True
show_traceback = True
pretty = True
color_output = True
error_summary = True
FYI: I mentioned this in my post on running tools on plugins: https://sureshjoshi.com/development/pants-plugin-code-quality#typechecking A lot of mypy problems come down to the same 2-3 root causes, and a missing init.py is one of the big ones
r
The thing is, turbocorp is a PEP420 namespace, it should not need a
__init__.py
file.
b
Haven't looked at the code, but there's always using an _`_init_.py`_ for an explicit namespace
r
Well, PEP420 is about implicit namespaces where there is no
__init__.py
. That said, I'll try pkgutil style namespace, I don't need to package my thing for a linux distrib 🙂 A summary of the different namespace styles: https://packaging.python.org/en/latest/guides/packaging-namespace-packages/
b
Right. We use explicit namespace packages because of technical reasons, but also the explicit is more obvious something is going on IMO
w
This is super interesting, I always thought it was just me who didn't like PEP420 (https://pypi.org/project/flake8-no-pep420/) 🙂
🙌 1
r
I like PEP420, but I have to say, I've had a lot of problems with different tools and systems with it 🙂
👍 1
e
Circling back, the answer here is 2 mypy settings that work together, you need both for PEP-420 support in Pants:
Copy code
[mypy]
namespace_packages = true
explicit_package_bases = true