On Pants 2.14, I'm noticing some new "Pants cannot...
# general
b
On Pants 2.14, I'm noticing some new "Pants cannot infer owners for the following imports" warnings. One is for a dependency in a Python test file, which is included in my
[pytest].extra_requirements
list, and another is for a type that is included in
[mypy].extra_type_stubs
, whose import is gated behind an
if TYPE_CHECKING
guard in the test file. This worked without issue in 2.13; is this a bug, or a legitimate new change in behavior? If the latter, what would be the recommended way to fix this? Thanks.
s
inference for extra_type_stubs has never worked - the change in 2.14 is that the default behavior for dependency-inference failures in general flipped from “ignore” to “warn”
if it’s gated behind an
if TYPE_CHECKING
then you can add a comment on the import line to explicitly disable dependency inference - I think the warning messages you’re seeing should include the comment
otherwise you can move your dependency from
extra_type_stubs
into your main requirements, and mark it as a type module
b
Interesting... is there special syntax for marking something as a type module?
s
yes, the
python_requirements
target has a
type_stubs_module_mapping
field: https://www.pantsbuild.org/docs/reference-python_requirements#codetype_stubs_module_mappingcode
if you list something there, pants will know its a type-stub module
Pants also guesses that anything starting/ending with
types
or
stubs
is a stubs module
👀 1
I actually have a PR open now to add this info to the docs: https://github.com/pantsbuild/pants/pull/17076 if you want to take a look and let me know if anything is confusing/missing 😅
b
Hrm... I think I may have misunderstood something... I had
pytest-mock
in
[pytest].extra_requirements
, which is what Pants was complaining about. The documentation for that field suggests it's more for plugins that pytest itself needs, rather than dependencies that the tests actually need.
s
oh! sorry, misread because I was working on the mypy issue
but the underlying problem is the same - the
python-infer
subsystem can’t “see” extra-requirements fields in other subsystems
b
No, you're good! I also had a mypy issue 😅
s
for the pytest thing, adding the comment suggested by the warning is the only work-around (I think)
b
moving the
pytest-mock
dependency into my main requirements file also appears to work.
🎉 2