able-school-92027
01/22/2025, 3:02 PMmypy
behavior when running pants check ::
Partition #1 - pants-2-19, ['CPython==3.9.*']:
<my_file.py>: error: Unexpected keyword argument "paths" for "Sandbox"; did you mean "path"? [call-arg]
Found 1 error in 1 file (checked 1 source file)
Partition #2 - pants-2-24, ['CPython==3.9.*']:
<my_file.py>: error: Unexpected keyword argument "path" for "Sandbox"; did you mean "paths"? [call-arg]
My my_file.py
looks like:
from pants.core.util_rules.adhoc_process_support import ExtraSandboxContents
from pants.version import Version, PANTS_SEMVER
class Sandbox(ExtraSandboxContents):
@staticmethod
def from_process(process: Process):
env_with_out_path: dict[str, str] = dict()
env_with_out_path.update(process.env)
env_with_out_path.pop("PATH", None)
if PANTS_SEMVER < Version("2.23.0"):
return Sandbox(
digest=process.input_digest,
path=process.env.get("PATH", None), <<< this is the prop when using pants<2.23.0
immutable_input_digests=process.immutable_input_digests,
append_only_caches=process.append_only_caches,
extra_env=FrozenDict(env_with_out_path),
)
return Sandbox(
digest=process.input_digest,
paths=(process.env.get("PATH", None),), <<< this is the new propery on pants>=2.23.0
immutable_input_digests=process.immutable_input_digests,
append_only_caches=process.append_only_caches,
extra_env=FrozenDict(env_with_out_path),
)
I had to add the if
for the version because the path
property of Sandbox
was replaced with paths
on pants 2.23 via https://github.com/pantsbuild/pants/commit/3b1ffb64bc2332e3925ffba387ce496143a4284d#diff-c440a5c58ef3255b75e7fb16e[…]7e2c3aba4567a95f44fa1edf8a4L139,
but it looks like mypy
is not being able to correctly run taking into consideration the pants version, as it fails on pants 2.19 with paths
doesn't exist in Sandbox
, and fails on pants 2.24 with path
doesn't exist in Sandbox
.
I do have the resolves
configured for each pants version, so that I can run lint, tests, check, etc, for both pants versions.
Does anyone know how to correctly run mypy
with multiple pants versions?broad-processor-92400
01/22/2025, 11:05 PMPANTS_SEMVER
is connected to the API shape of Sandbox
.
So, I think a # type: ignore[call-arg]
comment may be your best bet here: overrule mypy because you 'know more'broad-processor-92400
01/22/2025, 11:06 PMable-school-92027
01/23/2025, 12:58 PM