pants icon indicating copy to clipboard operation
pants copied to clipboard

Type-stub modules should not be included in PEXes outside of `./pants check`

Open danxmoran opened this issue 2 years ago • 1 comments

(Filing as a bug because the current behavior surprised me, but perhaps it's more of a feature request)

Describe the bug

We recently switched from using [mypy].extra_type_stubs to specifying stub libraries via python_requirements targets (because dependencies in extra_type_stubs aren't visible to the python-infer subsystem). After this change, I noticed that type-stub modules were being pulled into PEXes generated during ./pants test and ./pants package. This surprised me - I expected that any stub module (either inferred by Pants or explicitly marked via type_stubs_module_mapping) would only be included in the PEXes generated while running ./pants check.

Pants version

2.13.0

OS

Both

danxmoran avatar Sep 16 '22 14:09 danxmoran

I could see an argument for keeping the current behavior as the "safe" default - in this case I'd ask for a config toggle to enable excluding the stub requirements outside of check. If the toggle is enabled, any imports from stub libraries will need to be guarded by a check of if typing.TYPE_CHECKING

danxmoran avatar Sep 16 '22 14:09 danxmoran

I see this as us supporting a typecheck_deps field, which is only referenced for typechecking. Of course, that comes with a lot of Pants engine baggage, but I want us to ooch that direction anyways.

thejcannon avatar Oct 19 '22 14:10 thejcannon

This seems like it overlaps conceptually with https://github.com/pantsbuild/pants/issues/18320 (and the execution_dependencies/output_dependencies split for shell_command/adhoc_tool), being all different sorts of different "kinds" of dependencies.

I recall seeing a proposal (from @chrisjrn?) for a unification along the lines of dependencies=[":normal_dep", runnable(":runnable_dep")] and so maybe this could fit into the same pattern.

huonw avatar Mar 04 '23 00:03 huonw