Hey Pants Team, running into the following errors ...
# general
r
Hey Pants Team, running into the following errors running mypy for a multi project repository We have the following pants.toml configuration
Copy code
[mypy]
skip = true
config = "tools/python/mypy.ini"
extra_requirements.add = ['SQLAlchemy[mypy]==2.0.0']
lockfile = "tools/python/mypy.lock"
and the following mypy.ini
Copy code
[mypy]
plugins = sqlalchemy.ext.mypy.plugin
no_implicit_optional = True
local_partial_types = True
follow_imports = normal
disallow_untyped_defs = True
disable_error_code = misc
exclude = alembic
We added a new project that does not use sqlalchemy and now running mypy with pants we see the following errors:
Copy code
/Users/njgrisafi/.cache/pants/named_caches/pex_root/venvs/5bcbf65366e68d9647087f9935ca1efcc8fff5d1/b3aef238742d4e1a2d2b93cbfe8e2aa5b6944556/lib/python3.9/site-packages/mypy/typeshed/stdlib/fnmatch.pyi: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
/Users/njgrisafi/.cache/pants/named_caches/pex_root/venvs/5bcbf65366e68d9647087f9935ca1efcc8fff5d1/b3aef238742d4e1a2d2b93cbfe8e2aa5b6944556/lib/python3.9/site-packages/mypy/typeshed/stdlib/fnmatch.pyi: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
/Users/njgrisafi/.cache/pants/named_caches/pex_root/venvs/5bcbf65366e68d9647087f9935ca1efcc8fff5d1/b3aef238742d4e1a2d2b93cbfe8e2aa5b6944556/lib/python3.9/site-packages/mypy/typeshed/stdlib/fnmatch.pyi: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/tests/test_service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/tests/test_service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/tests/test_service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/cli/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/cli/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/cli/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
curious why it would even complain if the new package doesn't import sqlalchemy. Is it something wrong with the mypy.ini?
we run mypy in ci via
./pants check --no-mypy-skip tools/::
e
The errors show python3.9 is being used. What are your repo interpreter constraints?
r
okay a bit happier why I set the interpreter constraint
Copy code
Partition #1 - service-catalog, ['CPython<3.12,>=3.9']:
tools/python/service-catalog/tests/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/tests/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/tests/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/tests/test_service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/tests/test_service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/tests/test_service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/cli/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/cli/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/cli/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/service_catalog.py:21: error: Incompatible default for argument "unwanted_values" (default has type "None", argument has type "List[Any]")
tools/python/service-catalog/service_catalog/service_catalog.py:27: error: TypedDict key must be a string literal; expected one of ("name", "github_team", "slack_handle", "opsgenie_handle", "pagerduty_escalation_policy", ...)
tools/python/service-catalog/service_catalog/service_catalog.py:66: error: Argument 1 to "create_model_from_typeddict" has incompatible type "Type[Service]"; expected "Type[TypedDict]"
tools/python/service-catalog/service_catalog/service_catalog.py:78: error: Unsupported left operand type for + ("Set[str]")
tools/python/service-catalog/service_catalog/cli/utils.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/cli/utils.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/cli/utils.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/cli/utils.py:14: error: Argument 1 to "setLevel" of "Handler" has incompatible type "Optional[str]"; expected "Union[int, str]"
tools/python/service-catalog/service_catalog/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/__init__.py: note: See <https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports>
tools/python/service-catalog/service_catalog/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/cli/file_ownership.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/cli/file_ownership.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/cli/file_ownership.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/cli/file_ownership.py:45: error: Cannot find replacement for positional format specifier 0
tools/python/service-catalog/service_catalog/cli/main.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/cli/main.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/cli/main.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
Found 30 errors in 8 files (checked 7 source files)

Partition #2 - test-selection, ['CPython<3.12,>=3.9']:
Success: no issues found in 38 source files
but still that first partition fails?
h
Tangential, but are you using 3.9 and 3.10 and 3.11 in your codebase? You'll generally be happier if you restrict to a single interpreter minor version, if you can
r
let me give that a shot
Copy code
17:21:13.65 [ERROR] Completed: Typecheck using MyPy - mypy failed (exit code 1).
Partition #1 - service-catalog, ['CPython<3.10,>=3.9.5']:
tools/python/service-catalog/tests/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/tests/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/tests/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/tests/test_service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/tests/test_service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/tests/test_service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/cli/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/cli/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/cli/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/service_catalog.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/service_catalog.py:21: error: Incompatible default for argument "unwanted_values" (default has type "None", argument has type "List[Any]")
tools/python/service-catalog/service_catalog/service_catalog.py:27: error: TypedDict key must be a string literal; expected one of ("name", "github_team", "slack_handle", "opsgenie_handle", "pagerduty_escalation_policy", ...)
tools/python/service-catalog/service_catalog/service_catalog.py:66: error: Argument 1 to "create_model_from_typeddict" has incompatible type "Type[Service]"; expected "Type[TypedDict]"
tools/python/service-catalog/service_catalog/service_catalog.py:78: error: Unsupported left operand type for + ("Set[str]")
tools/python/service-catalog/service_catalog/cli/utils.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/cli/utils.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/cli/utils.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/cli/utils.py:14: error: Argument 1 to "setLevel" of "Handler" has incompatible type "Optional[str]"; expected "Union[int, str]"
tools/python/service-catalog/service_catalog/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/__init__.py: note: See <https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports>
tools/python/service-catalog/service_catalog/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/__init__.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/cli/file_ownership.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/cli/file_ownership.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/cli/file_ownership.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
tools/python/service-catalog/service_catalog/cli/file_ownership.py:45: error: Cannot find replacement for positional format specifier 0
tools/python/service-catalog/service_catalog/cli/main.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm"
tools/python/service-catalog/service_catalog/cli/main.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.attributes"
tools/python/service-catalog/service_catalog/cli/main.py: error: Cannot find implementation or library stub for module named "sqlalchemy.orm.decl_api"
Found 30 errors in 8 files (checked 7 source files)

Partition #2 - test-selection, ['CPython<3.10,>=3.9.5']:
Success: no issues found in 38 source files



āœ• mypy failed.
trying to narrow it down but still complaining about those stubs
h
Yeah, I wasn't expecting it to solve this, but that is a solid recommendation in general (e.g., it may speed up lockfile generation)
r
ahh okay good to know
h
So presumably at least one file in partition #2 depends on sqlalchemy, and is bringing in the implementation that way, whereas no file in partition #1 does?
r
yeah that is correct
those imports do not exists in those file at all
h
So the
sqlalchemy.ext.mypy.plugin
plugin expects to find sqlalchemy, and isn't, despite
extra_requirements.add = ['SQLAlchemy[mypy]==2.0.0']
šŸ‘ 1
I'll see if I can reproduce
r
I guess in as a temp fix we can add a
./pants check
command in CI per project point to different mypy.ini
qq: are we required to share a single mypy.ini per project?
or can we put one in each source root?
ahh seems like it does config discovery on top level pyproject.toml
so the work around is happy
Copy code
njgrisafi@Nicks-MacBook-Pro ~/workspace/rippling-main (jd-service-catalog)$ ./pants check --no-mypy-skip --mypy-config=tools/python/service-catalog/mypy.ini tools/python/service-catalog/::
17:39:28.25 [ERROR] Completed: Typecheck using MyPy - mypy failed (exit code 1).
tools/python/service-catalog/service_catalog/service_catalog.py:21: error: Incompatible default for argument "unwanted_values" (default has type "None", argument has type "List[Any]")
tools/python/service-catalog/service_catalog/service_catalog.py:27: error: TypedDict key must be a string literal; expected one of ("name", "github_team", "slack_handle", "opsgenie_handle", "pagerduty_escalation_policy", ...)
tools/python/service-catalog/service_catalog/service_catalog.py:66: error: Argument 1 to "create_model_from_typeddict" has incompatible type "Type[Service]"; expected "Type[TypedDict]"
tools/python/service-catalog/service_catalog/service_catalog.py:78: error: Unsupported left operand type for + ("Set[str]")
tools/python/service-catalog/service_catalog/cli/utils.py:14: error: Argument 1 to "setLevel" of "Handler" has incompatible type "Optional[str]"; expected "Union[int, str]"
tools/python/service-catalog/service_catalog/cli/file_ownership.py:45: error: Cannot find replacement for positional format specifier 0
Found 6 errors in 3 files (checked 7 source files)



āœ• mypy failed.
but yeah curious if this a bug
h
Glad you have a workaround, I'll still take a look at this in case it is a bug
šŸ‘ 1
r
yeah I think it will be easy to reproduce. I can help file an issue on this (currently AFK for the day)
h
That would be great, when you can