high-yak-85899
02/16/2022, 7:24 PMboto3
maps to boto3-stubs
and gets confused on imports. I can go manually add this dependency since it doesn't show up in too many places, but I'm surprised it's getting confused. I even updated my module_mapping
to try to force the resolution, but it wasn't happy.import boto3
import click
and dependencies is showing
//:boto3-stubs
//:click
boto3==1.17.0
botocore>=1.20.0,<2
in a requirements.txt
and
boto3-stubs>=1.21.0,<2
boto3-stubs[s3,ecr,sts]
in a requirements-dev.txt
If the dependency is a type stub, and the default does not work, seton thetype_stub_modules
target, andpython_requirement
on thetype_stubs_module_mapping
andpython_requirements
macros. (The default for type stubs is to strip offpoetry_requirements
,types-
,-types
, and-stubs
. So,stubs-
gives type stubs for the moduletypes-requests
.)requests
happy-kitchen-89482
02/16/2022, 7:59 PMhigh-yak-85899
02/16/2022, 9:24 PMdependencies
) since they'll never affect functionality.happy-kitchen-89482
02/16/2022, 10:05 PMhundreds-father-404
05/13/2022, 9:45 PMboto3-stubs
twice?
boto3-stubs>=1.21.0,<2
boto3-stubs[s3,ecr,sts]
Could you do boto3-stubs[s3,ecr,sts]>=1.21.0,<2
instead?
I only reproduce the issue when you have both stubs defined, and it's because it triggers ambiguity with dependency inference so Pants can't figure out which you wantdiff --git a/src/python/pants/util/BUILD b/src/python/pants/util/BUILD
index 76d0a50a8..64b634564 100644
--- a/src/python/pants/util/BUILD
+++ b/src/python/pants/util/BUILD
@@ -4,3 +4,6 @@
python_sources()
python_tests(name="tests")
+
+python_requirement(name="boto3", requirements=["boto3"])
+python_requirement(name="boto3-stubs", requirements=["boto3-stubs"])
diff --git a/src/python/pants/util/collections.py b/src/python/pants/util/collections.py
index 0dd3e3d90..4874ba5d5 100644
--- a/src/python/pants/util/collections.py
+++ b/src/python/pants/util/collections.py
@@ -8,7 +8,10 @@ import collections.abc
import gc
import math
from sys import getsizeof
-from typing import Any, Callable, Iterable, Iterator, MutableMapping, TypeVar
+from typing import Any, Callable, Iterable, Iterator, MutableMapping, TypeVar, TYPE_CHECKING
+
+if TYPE_CHECKING:
+ import boto3
from pants.engine.internals import native_engine
❯ ./pants dependencies src/python/pants/util/collections.py
src/python/pants/util:boto3
src/python/pants/util:boto3-stubs
high-yak-85899
05/13/2022, 9:46 PMboto3-stubs
, it only pulls in the most common stubs (which I think didn't include the specific ones I then had to call out).hundreds-father-404
05/13/2022, 9:46 PMboto3-stubs[s3,ecr,sts]>=1.21.0,<2
should do the trickhigh-yak-85899
05/13/2022, 9:49 PM