https://pantsbuild.org/ logo
#general
Title
# general
r

ripe-cpu-85141

08/06/2022, 1:59 AM
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

wide-midnight-78598

08/06/2022, 3:09 AM
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

ripe-cpu-85141

08/06/2022, 3:39 AM
The thing is, turbocorp is a PEP420 namespace, it should not need a
__init__.py
file.
b

bitter-ability-32190

08/06/2022, 10:41 AM
Haven't looked at the code, but there's always using an _`_init_.py`_ for an explicit namespace
r

ripe-cpu-85141

08/06/2022, 1:20 PM
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

bitter-ability-32190

08/06/2022, 1:53 PM
Right. We use explicit namespace packages because of technical reasons, but also the explicit is more obvious something is going on IMO
w

wide-midnight-78598

08/07/2022, 12:23 AM
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

ripe-cpu-85141

08/07/2022, 2:20 PM
I like PEP420, but I have to say, I've had a lot of problems with different tools and systems with it 🙂
👍 1
e

enough-analyst-54434

08/20/2022, 6:20 PM
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
3 Views